Patrick Doyle wrote:
> If you look in app/controllers/application.rb, you will find that
> ApplicationController is a task that you derived from
> ActionController::Base.  You should be able to find documentation about
> ActionController::Base at http://api.rubyonrails.org/

ah.  This solves the first mystery.  Still learning all the stuff that 
gets generated with scaffold.

> From one newbie to another...
> Look at the links created in the index view for your tasks controller. 
> With
> the default scaffold, you should see three links to the right of each 
> task
> listed: Show, Edit, and Destroy.  If you mouse-over the Edit link, you 
> will
> probably see something that looks like: 
> http://localhost:3000/tasks/1/edit.
> That says to the routing system in Rails (through the magic of the code 
> you
> wrote in config/routes.rb) 

hmm. If I look at the routes that were auto-generated for me, I see:
  map.connect ':controller/:action/:id'

which would lead me to believe that the URL should be:
http://localhost:3000/tasks/edit/1

while semantically it makes more sense to apply the edit action last, I 
don't see how that maps to the code.  Is it considered bad practice to 
leave these as is. The comment says "consider removing the them or 
commenting them out if you're using named routes and resources."  I'm 
not quite sure what "named routes and resources" are and whether I'm 
using them.

>"Invoke the 'edit' action in the 'tasks'
> controller, and, by the way, set the 'id' parameter to '1'".
> 
> When your #edit action is invoked, it searches the Task table in your
> database for the entry with an ID of 1.  Then Rails, by default, will 
> render
> a view (a web page) named "edit".  You can see the template for that web
> page in app/views/edit.html.erb.
> 
> If you completely remove the #edit action, the default behavior is still 
> to
> render a template with the same name as the action.

Yes, it does this, but when the template is rendered, it causes the 
error below, which I assume is because '@task' is not defined, although 
I don't really understand the error message.

Called id for nil, which would mistakenly be 4 -- if you really wanted 
the id of nil, use object_id

Extracted source (around line #3):

1: <h1>Editing task</h1>
2:
3: <% form_for(@task) do |f| %>
4:   <%= f.error_messages %>
5:
6:   <p>


> If you leave the #edit action in there, but don't do anything in it, the
> default behavior is still to render a template with the same name as the
> action.

yup.  same behavior.

> If you leave the code in there as written, the #edit action will fetch 
> the
> row from the Task database with the specified ID.  The #edit view will 
> then
> have some data to show when it displays the form.

Makes sense.

I see empirically how it works; however, I'm still curious how does 
Rails "know" whether I've called respond_to in my edit method?

Thanks so much,
Sarah
-- 
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 post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to