In an *.rhtml, why do I need to add <% for product in @products %> in order that I may call an <img class="list-image" src="<%product.img_url %>"/>. Is there not another way to skip the "for product" line? I really dont want to include it. I tried @products product but it does not work. Can anyone help shed light on this matter? -- Posted via http://www.ruby-forum.com/.
Guest wrote:> In an *.rhtml, why do I need to add <% for product in @products %> in > order that I may call an <img class="list-image" src="<%> product.img_url %>"/>. Is there not another way to skip the "for > product" line? I really dont want to include it. I tried @products > product but it does not work. Can anyone help shed light on this matter?Or better, how can I extract the data from the SQL Database one at a time without using a for loop? -- Posted via http://www.ruby-forum.com/.
Guest wrote:> In an *.rhtml, why do I need to add <% for product in @products %> in > order that I may call an <img class="list-image" src="<%> product.img_url %>"/>. Is there not another way to skip the "for > product" line? I really dont want to include it. I tried @products > product but it does not work. Can anyone help shed light on this matter? > >Hi, what do you want to do? <% for product in @products %> will basically cause you to iterate over the list of products, one at a time.. @products is a list (array) and at any give iteration of the loop ''product'' is one of the elements in the array.. Cheers, Mohit.
if think you want to use @product = Product.find(:first) instead of @products = Product.find(:all) 2006/8/7, Mohit Sindhwani <mo_mail@onghu.com>:> > Guest wrote: > > In an *.rhtml, why do I need to add <% for product in @products %> in > > order that I may call an <img class="list-image" src="<%> > product.img_url %>"/>. Is there not another way to skip the "for > > product" line? I really dont want to include it. I tried @products > > product but it does not work. Can anyone help shed light on this matter? > > > > > Hi, what do you want to do? > > <% for product in @products %> will basically cause you to iterate over > the list of products, one at a time.. > @products is a list (array) and at any give iteration of the loop > ''product'' is one of the elements in the array.. > > Cheers, > Mohit. > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Michael Siebert <info@siebert-wd.de> www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060807/8adf9888/attachment.html
Michael Siebert wrote:> if think you want to use @product = Product.find(:first) instead of > @products = Product.find(:all) > > 2006/8/7, Mohit Sindhwani <mo_mail@onghu.com>: >> >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > > -- > Michael Siebert <info@siebert-wd.de> > > www.stellar-legends.de - Weltraum-Browsergame im Alpha-StadiumWell, this is a simple template of an list.rhtml [CODE] <h1>Listare Carti</h1> <table> <th>Titlu</th> <th>Subtitlu</th> <th>Autor(i)</th> <th>Editura</th> <th>ISBN</th> <th>Numar Inventar</th> <th>URL Imagine</th> <th>Data</th> </tr> <% for book in @books %> <tr> <% for column in Book.content_columns %> <td><%=h book.send(column.name) %></td> <% end %> <td><%= link_to ''Arata'', :action => ''show'', :id => book %></td> <td><%= link_to ''Modifica'', :action => ''edit'', :id => book %></td> <td><%= link_to ''Sterge'', { :action => ''destroy'', :id => book }, :confirm => ''Are you sure?'', :post => true %></td> </tr> <% end %> </table> <%= link_to ''Pagina Anterioara'', { :page => @book_pages.current.previous } if @book_pages.current.previous %> <%= link_to ''Pagina Urmatoare'', { :page => @book_pages.current.next } if @book_pages.current.next %> <br /> <%= link_to ''Adauga Carte'', :action => ''new'' %> [CODE] I want to replace the "<% for column in Book.content_columns %> <td><%=h book.send(column.name) %></td>" so that I would be able to controll the content myself, and insert an image far into the left of the table. How can I do that? -- Posted via http://www.ruby-forum.com/.
I don''t want to offend you, but i think you should read a bit more about what the scaffolding does. I''d recommend the "Four Days On Rails" PDF (don''t have a link, find it on Google). greetz 2006/8/7, Guest <mail@mail.com>:> > Michael Siebert wrote: > > if think you want to use @product = Product.find(:first) instead of > > @products = Product.find(:all) > > > > 2006/8/7, Mohit Sindhwani <mo_mail@onghu.com>: > >> > >> Rails mailing list > >> Rails@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > > > > > > > -- > > Michael Siebert <info@siebert-wd.de> > > > > www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium > > Well, this is a simple template of an list.rhtml > > [CODE] > <h1>Listare Carti</h1> > > <table> > <th>Titlu</th> > <th>Subtitlu</th> > <th>Autor(i)</th> > <th>Editura</th> > <th>ISBN</th> > <th>Numar Inventar</th> > <th>URL Imagine</th> > <th>Data</th> > </tr> > > <% for book in @books %> > <tr> > <% for column in Book.content_columns %> > <td><%=h book.send(column.name) %></td> > <% end %> > <td><%= link_to ''Arata'', :action => ''show'', :id => book %></td> > <td><%= link_to ''Modifica'', :action => ''edit'', :id => book %></td> > <td><%= link_to ''Sterge'', { :action => ''destroy'', :id => book }, > :confirm => ''Are you sure?'', :post => true %></td> > </tr> > <% end %> > </table> > > <%= link_to ''Pagina Anterioara'', { :page => @book_pages.current.previous > } if @book_pages.current.previous %> > <%= link_to ''Pagina Urmatoare'', { :page => @book_pages.current.next } if > @book_pages.current.next %> > > <br /> > > <%= link_to ''Adauga Carte'', :action => ''new'' %> > [CODE] > > I want to replace the "<% for column in Book.content_columns %> <td><%=h > book.send(column.name) %></td>" so that I would be able to controll the > content myself, and insert an image far into the left of the table. How > can I do that? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Michael Siebert <info@siebert-wd.de> www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060807/1a387b46/attachment.html
Guest wrote:> Michael Siebert wrote: > >> if think you want to use @product = Product.find(:first) instead of >> @products = Product.find(:all) >> >> 2006/8/7, Mohit Sindhwani <mo_mail@onghu.com>: >> >>> Rails mailing list >>> Rails@lists.rubyonrails.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >> >> -- >> Michael Siebert <info@siebert-wd.de> >> >> www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium >> > > Well, this is a simple template of an list.rhtml > > [CODE] > <h1>Listare Carti</h1> > > <table> > <th>Titlu</th> > <th>Subtitlu</th> > <th>Autor(i)</th> > <th>Editura</th> > <th>ISBN</th> > <th>Numar Inventar</th> > <th>URL Imagine</th> > <th>Data</th> > </tr> > > <% for book in @books %> > <tr> > <% for column in Book.content_columns %> > <td><%=h book.send(column.name) %></td> > <% end %> > <td><%= link_to ''Arata'', :action => ''show'', :id => book %></td> > <td><%= link_to ''Modifica'', :action => ''edit'', :id => book %></td> > <td><%= link_to ''Sterge'', { :action => ''destroy'', :id => book }, > :confirm => ''Are you sure?'', :post => true %></td> > </tr> > <% end %> > </table> > > <%= link_to ''Pagina Anterioara'', { :page => @book_pages.current.previous > } if @book_pages.current.previous %> > <%= link_to ''Pagina Urmatoare'', { :page => @book_pages.current.next } if > @book_pages.current.next %> > > <br /> > > <%= link_to ''Adauga Carte'', :action => ''new'' %> > [CODE] > > I want to replace the "<% for column in Book.content_columns %> <td><%=h > book.send(column.name) %></td>" so that I would be able to controll the > content myself, and insert an image far into the left of the table. How > can I do that? > >Ah! That makes sense now :) <% for column in Book.content_columns %> <td><%=h book.send(column.name) %></td> <% end %> This is basically from the scaffold which does not know which columns you actually have in the database and instead queries the database to find the information about the columns... You can replace it with code that is something like this: <table> <th>Titlu</th> <th>Subtitlu</th> <th>Autor(i)</th> <th>Editura</th> <th>ISBN</th> <th>Numar Inventar</th> <th>URL Imagine</th> <th>Data</th> </tr> <% for book in @books %> ### This iterates over the books... <tr> ### replace the second iteration of "for column in Book.content_columns" with -- <td><%=h book.titlu %></td> ### this outputs the actual field.. <td><%=h book.Subtitlu %></td> ### this outputs the actual field.. <td><%=h book.Autor %></td> ### this outputs the actual field.. .... </tr> ## <% end %> ### this ends the iteration of book in @books.. Hope this helps, Mohit
>> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > > -- > Michael Siebert <info@siebert-wd.de> > > www.stellar-legends.de - Weltraum-Browsergame im Alpha-StadiumNo offence taken, thanks for the advice, found the book and started reading. -- Posted via http://www.ruby-forum.com/.