On Sun, May 24, 2009 at 11:32 AM, SpringFlowers AutumnMoon
<rails-mailing-l...@andreas-s.net> wrote:
>
> we use
>
> (1..10).each do |i|
>  p i
> end
>
> so that a value is "yield" to i in a block...
>
> but what about
>
> <% form_for @story do |f| %>
>  <%= f.text_field %>
> <% end %>
>
> there is no loop at all... why do we need to make it look like a loop?
> Can't we do it without making it look like a loop?  (write in another
> way)?
>
> Also, must be use a Story instance here?  Can't we just use :story and
> achieve the same result?  The @story instance is just newly created and
> has no data at all -- does it actually help creating the form?  Can't
> :story suffice already?  thanks.

Both these examples of code use blocks, the first just happens to be a
loop, the second only looks like a loop if your first experience of
blocks is in loops.

I think it's important that you forget about the loop and focus on
blocks, once you've understood blocks, it will no longer look like a
loop and you'll understand that you really don't want to write it a
different way (even though it's possible)

Yes, you can use @story or :story and form_for will figure it out for you.
Mostly it depends on where you're using the form, new or edit etc.

Andrew Timberlake
http://ramblingsonrails.com

http://MyMvelope.com - The SIMPLE way to manage your savings

--~--~---------~--~----~------------~-------~--~----~
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