diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-10-21 18:33:40 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-10-21 18:33:40 +0100 |
commit | a03e2b356c66ddc8809fa2b23a2a7d652f173b8b (patch) | |
tree | ab8552913475bf94a78e4cbfbae804b2ecd9eca2 /railties/doc/guides/source/actioncontroller_basics/methods.txt | |
parent | 18542c9e00209679bdaacf64075819fb887ec856 (diff) | |
download | rails-a03e2b356c66ddc8809fa2b23a2a7d652f173b8b.tar.gz rails-a03e2b356c66ddc8809fa2b23a2a7d652f173b8b.tar.bz2 rails-a03e2b356c66ddc8809fa2b23a2a7d652f173b8b.zip |
Merge with docrails. Also add a rake task to generate guides in your rails application :
rake doc:guides
The rake task will generate guides inside doc/guides directory of your application. Open index.html to browse.
Diffstat (limited to 'railties/doc/guides/source/actioncontroller_basics/methods.txt')
-rw-r--r-- | railties/doc/guides/source/actioncontroller_basics/methods.txt | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/railties/doc/guides/source/actioncontroller_basics/methods.txt b/railties/doc/guides/source/actioncontroller_basics/methods.txt new file mode 100644 index 0000000000..a1ef204adb --- /dev/null +++ b/railties/doc/guides/source/actioncontroller_basics/methods.txt @@ -0,0 +1,37 @@ +== Methods and actions == + +A controller is a Ruby class which inherits from ActionController::Base and has methods just like any other class. Usually these methods correspond to actions in MVC, but they can just as well be helpful methods which can be called by actions. When your application receives a request, the routing will determine which controller and action to run. Then an instance of that controller will be created and the method corresponding to the action (the method with the same name as the action) gets run. + +[source, ruby] +---------------------------------------------- +class ClientsController < ActionController::Base + + # Actions are public methods + def new + end + + # These methods are responsible for producing output + def edit + end + +# Helper methods are private and can not be used as actions +private + + def foo + end + +end +---------------------------------------------- + +Private methods in a controller are also used as filters, which will be covered later in this guide. + +As an example, if the user goes to `/clients/new` in your application to add a new client, a ClientsController instance will be created and the `new` method will be run. Note that the empty method from the example above could work just fine because Rails will by default render the `new.html.erb` view unless the action says otherwise. The `new` method could make available to the view a `@client` instance variable by creating a new Client: + +[source, ruby] +---------------------------------------------- +def new + @client = Client.new +end +---------------------------------------------- + +The Layouts & rendering guide explains this in more detail. |