Praveen BK wrote in post #1108907:> When should I create a new controller in a rails application?
Basically the same as in any other MVC based system. When you need to
manage user actions and communicate information between views and
models.
The most common pattern is to have a controller with the seven
"RESTful"
actions (index, new, show, edit, create, update & destroy) for each
model object. The actions map to HTTP requests, and depend on the HTTP
method used (i.e. GET, POST, DELETE, PUT/PATCH).
For example sending a GET request to http://example.com/articles would
map to the "index" action of articles_contolller.rb. The
"index" action
retrieves a list of article model instances and passes the list to the
app/views/index.html.erb view template for rending into a web browser.
In a RESTful application you want to think about breaking down your
application''s model into "resources" Sometimes a
"resource" is basically
a model object, such as Article.
Often a resource is more abstract and can be treated independently from
actual model classes with their own MVC. One example of this would be a
user session. There may be no model object representing the concept of a
session, but there could still be an MVC for managing session in a
RESTful style. In other words you would have an entry in
config/routes.rb for a sessions resource with a sessions_controller.rb
file with at least some of the standard RESTful actions. Maybe a
"create" action for logging in users by creating a session for them
and
a "destroy" action for logging users out. There may be no actual
persistent model representing a session, but rather the model may be
nothing more than inserting the id of the user model into the session
hash.
There are also many other opportunities for resources that don''t map
directly to models or views. Or you may choose to use a separate
resource (and controller) for managing AJAX requests, or advanced search
features. The possibilities are endless and depend greatly on the needs
of your application.
If you have not done so already, begin with the Rails guides:
http://guides.rubyonrails.org/index.html
Once you have a general understanding of Rails then jump into on of the
excellent tutorials such as:
http://ruby.railstutorial.org
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.