I'm desperate. I've read and tried many things with rails. The problem isn't that "big", it is just that I'm still getting used to the convention over conf world. Lack of examples, too.
I just want to be able to have a site where you have roles (think admin, normal user, etc) and each of these can view,say, posts, articles. However, the admin obviously has access to update/delete posts,articles. Users only post, things like that.
I can create the authentications, sessions, and all. But I don't know how to present (or refactor) code. Where does the code for the admin go? views?, what about for users?
Would I need to create controllers specifically for admins, and users, others, in order to display the same model objects (articles, posts) that I'll be dealing with? including views?
Thanks
There's a free Railscast that may help you with this called "Authorization with CanCan".
If you feel like parting with some money, Rails 3 in Action also covers this sort of thing in Chapters 6 and 7.
First, watch this screencast: Where administration goes.
Second, watch this one: Restricting Access.
Then this one: Super Simple Authentication.
This should clear up your confusion and help you wrap your mind around "The Rails Way" of doing authentication and administration.
Once your immediate crisis is over, I would STRONGLY recommend you pick up a copy of "Beginning Rails 3". The kind of frustration you're experiencing is normal: when you come from the world of basic HTML plus scripting (javascript and php most likely) it's really hard to "get" the big idea that a framework imposes on your design.
Beginning Rails 3 takes about 2-3 days to work completely through, front to back. When you're done you'll TRULY understand Rails and your work will feel like FUN, not frustration. It's really, really, really, really worth it to take the time to read the book. 2-3 days with the book will save you 2-3 months of mediocre coding and learning by trial and error.
There are lots of examples available. One of the best sources of information is Railscasts. You will find many screencasts on authentication (including the most recent (#250), as chance would have it). You will also find them on authorization, which is the role-based mechanism you describe.
Here's a pretty thorough comparison of many authorization plugins: http://steffenbartsch.com/blog/2008/08/rails-authorization-plugins/
I would also look into cancan (railscast), which is newer than that list and highly regarded.
Related
I'm a pretty big RoR novice but I've had a lot of problems with finding out even where to begin.
I'm looking for any tutorials or examples of apps that lets a user fill out a simple form in ruby, takes that information, redirects to another page, and posts the information. The user would be able to share that unique link with others, which shows that information.
I've taken a look at various gems such as Formtastic and Simpleforms but the tutorials on Railscast are outdated and it's difficult to get working. I believe it's because I'm on Rails 3.
I'm pretty lost here and if anything can just prod me in the general direction of where to start / give me general strategy of how I should tackle this, it'd be greatly appreciated. This seems incredibly easy but I'm making it harder for myself than what it is.
I'm actually looking to take an intensive RoR course in a few weeks but I need to get this simple MVP app done (it'll include video by nimbb API) for a deadline... so while I should definitely be putting in the effort to learn rather than cheat and drift, your help this time around would really be great :)
To a large extent this functionally is baked into rails. The simplest way to do this is without any extra gems (besides the default ones):
In your terminal run:
rails g scaffold form name:string message:text
Then the user can go to example.com/forms/new and enter their info. Once they submit the form rails auto redirects them to the view page for that new data. The URL of that page which will be something like /forms/n where n is some integer is the link to share.
If your struggling with rails concepts I would look at the rails guides, especially: http://guides.rubyonrails.org/getting_started.html
I have a really stupid question in my mind.
I have used Wordpress to create a website for long time, but I dont want to use it anymore. And now I am looking for little bit different approach. Otherwise, I am quite new in Ruby on Rails. I have read some books and I am not feeling in this matter so confident. So, here is the deal:
My friend asked me to create a simple website for his company. He wants only super simple static website which will contains these pages:
Home
Products
Contact
Each page will contain simple information and there is no need to implement contact forms and other basic functionalities. I also want to deploy this app on Heroku, because he has not a lot of money and we are looking for free hosting. Moreover, I think that the best approach in this matter will be some kind of CMS which will help him to edit the website.
The overview of final solution:
Static webpages with simple CMS
Using twitter bootstrap for basic layout
Deploy on Heroku
I appreciate every contribution in this matter.
Thank you
Everything you have said suggests that you should stick with WordPress. It's perfectly capable of presenting a non-blog static website (use Pages instead of Posts) and there are some excellent themes available. WP has, over the years really become a CMS that's also good for blogging. There are other tools like Drupal that may be appropriate.
I set up a WP site with almost exactly the same goals for some very non-technical people; with a little training they eventually learned how to manage the site, upload images, add content, grant permissions to others, and do a lot of other pretty cool stuff. I have been using Rails since 2007, but for that case, it was not the right solution.
Rails is a very (very!) sophisticated web development environment used to build complex and scalable dynamic websites. With power comes a level of complexity several orders of magnitude higher than WordPress. Even if you use refinerycms you still need to do a lot of complicated setup, and need to know a lot of stuff. Even if you're using Heroku and following a RailsCast like the one for refinerycms, you'll undoubtedly hit some wall where you really need to understand more ... Rails is alluring this way -- seems simple.
If you are using this a reason to learn Rails, and are willing to invest some time, then by all means go for it. But if you want a simple solution, it's not the way. Learning Rails is like learning to fly a plane, but harder.
For static pages with rails, you can use High Voltage gem. You can find the detailed usage of this gem in this blog post . Once you create the pages, then you can easily deploy your app as like normal rails app in the heroku.
I'm still learning rails but want to be sure I'm heading in the right direction. For several of my models I want to let a list of users know that updates have been made when a new record is created for example. I'd like to tie this to an email and in-app notification(doesn't need to be AJAX), next page refresh is fine.
I've been reading up on observers some and I think that's what I want but they seem somewhat controversial based on the blogs I've read. Services like Pusher seem to be overkill for my needs.
Would this be a good solution for this scenario? Also, can anyone point me to some example code that I could emulate?
Thanks!
Check out Rails Cast if you are trying to learn. Best free code base I have seen. Also check out this book another great learning tool. Agile Web Development with Rails (2nd edition).There might be some newer ones out but I have not checked.
My site requires authentication, so it has membership. I wonder if I should create my own comment system for user to discuss/comment on an article, or should just use third-party comment system like Disqus or Intense Debate, which requires seperate account (Twitter, Facebook, etc.).
In fact, it would be good if there is a guide to create my own comment system or Q&A system for users to discuss a particular article on my website. If you know of any, please lemme know.
Thanks.
I recently am working on a project where I had to weigh the same things. I eventually decided to roll my own comments.
Namely the advantage of rolling your own is that you have full control on how they work. I needed a moderation system/queue that I needed to work a specific way, for one. Second, someday I will be looking to integrate a 'community reputation' system, so that was another plus for rolling my own. Such things I don't want to leave to a third party solution outside of my control and the third parties don't always have such a flexible API to modify.
On the other hand, Disqus (or similar third party commenting systems) may be up your alley if your needs are more simple. For one, it's easy to get up and running and may be all you may really need. Accounts for it work across anything using Disqus, and that may win convenience points for your users who are sick and tired of having to sign up for a million accounts for a million websites. Disqus also has built in tools (for spam, trolls, etc) and that is also convenient.
If you go with rolling your own solution with user accounts, you can integrate things like Facebook/Twitter/etc login to make the registration process easier. But overall, like I said, depends on how fancy or complex you need the whole thing to be.
Should you roll your own, a good start is a recent Railscasts episode on the Ancestry gem http://railscasts.com/episodes/262-trees-with-ancestry, it should give you a good start on building threaded comments.
Something in the middle :) Use the acts_as_commentable plugin :
https://github.com/jinzhu/acts_as_commentable
Most of the time, whenever I hit a website that looks "bubbly" in nature, and all prettified in those pastel-like colors, I think to myself, "This was probably done with Rails." And, lo and behold, after some digging into the site's information pages I discover this is actually true. So, I pose the question, not knowing much about Rails but enough about Django to understand how the database stuff works:
Does RoR have any display-specific qualities that affect how a web page looks? Or do all RoR devs naturally use the same Adobe tools to make everything look so ubiquitous?
Ruby on Rails is a server side technology, so it doesn't lend any specific quality to the user visible design. That said, it is a "trendy" technology so people who are likely to write their back-end code with RoR are likely to choose a particular "Web 2.0" style for their views.
As a Ruby on Rails developer, I can tell you that most Ruby on Rails developers are passionate about their work and we pay a lot of attention to details when building websites as much backend as front end. Its not just a trend, its a way of thinking and working.
No, it hasn't any display-specific qualities.
The theory is that RoR makes that backend stuff easier, so more time can, and apparently is, spent on the front end stuff.
Its all done with Mirrors. And CSS. :)
Rails is a very popular Web framework, it's just be coincidence that all the ones you've looked at have been rails apps.
What kind of sites have you been looking at to draw this hypothesis?
that's a funny question with a funny description :) ... bubbly!
As a madman, I develop with RoR, it's kind of rule in our area. We learn madness from the beginning, as a result of http://railsforzombies.org...
May wise men follow a wise path!
Short Answer: NO
However...
As a Rails developer I can say that due to the Agile nature of Rails and the speed in which you can develop web applications with Rails I do find myself having more time freed up on a project to spend polishing the user interface. I believe this may be a reason you often see more polished looking Rails sites.
So in my mind I believe your choice of framework can have a direct correlation to the end product that is produced!
Rails does add some stuff to the front end. Like to every html form, it will add a hidden input element authenticity_token.
You can also tell because rails URLs and form actions will never end with suffixes like .aspx or .php or .html or .jsp, and they won't usually append ?query=book&encoding=utf8 like you see on google. And they won't usually have superlong crufties like you see on amazon (eg http://www.amazon.com/Agile-Web-Development-Rails-Ruby/dp/1934356549/ref=sr_1_1?ie=UTF8&qid=1297922135&sr=8-1). Instead Rails prefers simple routing URLs. If amazon were written in rails, you might instead expect amazon.com/books/Agile-Web-Development-Rails-Ruby
So there are ways to spot a Rails app. I expect other web frameworks, especially the ones that emulate rails, would duplicate some or all of these features, so this isn't a sure-fire method, but it helps.