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 <h1>Listing posts</h1> <table> <tr> <th>Name</th> <th>Title</th> <th>Content</th> <th></th> <th></th> <th></th> </tr> <% @posts.each do |post| %> <tr> <td><%= post.name %></td> <td><%= post.title %></td> <td><%= post.content %></td> <td><%= link_to ''Show'', post %></td> <td><%= link_to ''Edit'', edit_post_path(post) %></td> <td><%= link_to ''Destroy'', post, :confirm => ''Are you sure?'', :method => :delete %></td> </tr> <% end %> </table> <br /> <%= 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) <td><%= post.name %></td> <td><%= post.title %></td> <td><%= post.content %></td> (is it will get a values from database?) Thanks -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Look at the code on posts_controller.rb index method On Sat, Apr 23, 2011 at 12:10 PM, amrit pal pathak < amritpalpathak1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > > > > <h1>Listing posts</h1> > > <table> > <tr> > <th>Name</th> > <th>Title</th> > <th>Content</th> > <th></th> > <th></th> > <th></th> > </tr> > > <% @posts.each do |post| %> > <tr> > <td><%= post.name %></td> > <td><%= post.title %></td> > <td><%= post.content %></td> > <td><%= link_to ''Show'', post %></td> > <td><%= link_to ''Edit'', edit_post_path(post) %></td> > <td><%= link_to ''Destroy'', post, :confirm => ''Are you > sure?'', :method => :delete %></td> > </tr> > <% end %> > </table> > > <br /> > > <%= 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) <td><%= post.name %></td> > <td><%= post.title %></td> > <td><%= post.content %></td> > > (is it will get a values from database?) > > Thanks > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Thanks: Rajeev sharma -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 <rajeevsharma86-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Look at the code on posts_controller.rb index method > > On Sat, Apr 23, 2011 at 12:10 PM, amrit pal pathak < > amritpalpathak1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> 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 >> >> >> >> <h1>Listing posts</h1> >> >> <table> >> <tr> >> <th>Name</th> >> <th>Title</th> >> <th>Content</th> >> <th></th> >> <th></th> >> <th></th> >> </tr> >> >> <% @posts.each do |post| %> >> <tr> >> <td><%= post.name %></td> >> <td><%= post.title %></td> >> <td><%= post.content %></td> >> <td><%= link_to ''Show'', post %></td> >> <td><%= link_to ''Edit'', edit_post_path(post) %></td> >> <td><%= link_to ''Destroy'', post, :confirm => ''Are you >> sure?'', :method => :delete %></td> >> </tr> >> <% end %> >> </table> >> >> <br /> >> >> <%= 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) <td><%= post.name %></td> >> <td><%= post.title %></td> >> <td><%= post.content %></td> >> >> (is it will get a values from database?) >> >> Thanks >> >> -- >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > > > -- > Thanks: > Rajeev sharma > > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.