Help to understand scaffold's code!

Follwed a Guide at
http://guides.rubyonrails.org/getting_started.html.Generated
a scafffold as

rails generate scaffold Post name:string title:string content:text
The content of app/view/posts/
index.html.erb file are as under

Listing posts

<% @posts.each do |post| %>

<% end %>
Name Title Content
<%= post.name %> <%= post.title %> <%= post.content %> <%= link_to 'Show', post %> <%= link_to 'Edit', edit_post_path(post) %> <%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %>

<%= link_to ‘New Post’, new_post_path%>

                       Now look at following  line of code,and

please help me to understand it

  1. <% @posts.each do |post| %>
    is it will execute when at least one post will be created??)

  2. <%= post.name %> <%= post.title %> <%= post.content %>

(is it will get a values from database?)

Thanks

Look at the code on posts_controller.rb index method

On Sat, Apr 23, 2011 at 12:10 PM, amrit pal pathak <
[email protected]> wrote:

Listing posts

<% end %>

“Ruby on Rails: Talk” group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Thanks:
Rajeev sharma

See in app/controller/post_controller.rb file

in that there is a code for index in

def index
.
.
.

end

when you make any request above function will call first and then goes
to
index.html.erb file.
Now you can explore more things by tracing the code.

On Sat, Apr 23, 2011 at 12:16 PM, rajeevsharma86

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs