# Syntax Problem

**URL:** <https://www.ruby-forum.com/t/syntax-problem/101672>\
**Category:** Rails\
**Created:** [August 7, 2006, 10:27am UTC](https://www.ruby-forum.com/t/syntax-problem/101672 "2006-08-07T10:27:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [August 7, 2006, 10:27am UTC](https://www.ruby-forum.com/t/syntax-problem/101672/1 "2006-08-07T10:27:40Z")

</div>

In an \*.rhtml, why do I need to add \<% for product in @products %\> in  
order that I may call an ![](). 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?

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [August 7, 2006, 10:41am UTC](https://www.ruby-forum.com/t/syntax-problem/101672/2 "2006-08-07T10:41:28Z")

</div>

Guest wrote:

> In an \*.rhtml, why do I need to add \<% for product in @products %\> in  
> order that I may call an ![](). 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?

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [August 7, 2006, 10:45am UTC](https://www.ruby-forum.com/t/syntax-problem/101672/3 "2006-08-07T10:45:11Z")

</div>

Guest wrote:

> In an \*.rhtml, why do I need to add \<% for product in @products %\> in  
> order that I may call an ![](). 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.

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [August 7, 2006, 10:51am UTC](https://www.ruby-forum.com/t/syntax-problem/101672/4 "2006-08-07T10:51:11Z")

</div>

if think you want to use @product = Product.find(:first) instead of  
@products = Product.find(:all)

2006/8/7, Mohit S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Michael S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

[www.stellar-legends.de](http://www.stellar-legends.de) - Weltraum-Browsergame im Alpha-Stadium

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [August 7, 2006, 11:18am UTC](https://www.ruby-forum.com/t/syntax-problem/101672/5 "2006-08-07T11:18:17Z")

</div>

Michael S. wrote:

> if think you want to use @product = Product.find(:first) instead of  
> @products = Product.find(:all)
> 
> 2006/8/7, Mohit S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> –  
> Michael S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> [www.stellar-legends.de](http://www.stellar-legends.de) - Weltraum-Browsergame im Alpha-Stadium

Well, this is a simple template of an list.rhtml

[CODE]

# Listare Carti

\<% for book in @books %\>

 \<% for column in Book.content\_columns %\> \<% end %\> \<% end %\>

| Titlu | Subtitlu | Autor(i) | Editura | ISBN | Numar Inventar | URL Imagine | Data |
| --- | --- | --- | --- | --- | --- | --- | --- |
| \<%=h book.send(column.name) %\> | \<%= link\_to 'Arata', :action =\> 'show', :id =\> book %\> | \<%= link\_to 'Modifica', :action =\> 'edit', :id =\> book %\> | \<%= link\_to 'Sterge', { :action =\> 'destroy', :id =\> book }, :confirm =\> 'Are you sure?', :post =\> true %\> |

\<%= 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 %\>

  

\<%= link\_to ‘Adauga Carte’, :action =\> ‘new’ %\>

[CODE]

I want to replace the “\<% for column in Book.content\_columns %\> \<%=h  
book.send(column.name) %\>” 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?

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [August 7, 2006, 11:27am UTC](https://www.ruby-forum.com/t/syntax-problem/101672/6 "2006-08-07T11:27:14Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > >
> 
> [CODE]
> 
> Data :confirm =\> 'Are you sure?', :post =\> true %\>
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Michael S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

[www.stellar-legends.de](http://www.stellar-legends.de) - Weltraum-Browsergame im Alpha-Stadium

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [August 7, 2006, 12:11pm UTC](https://www.ruby-forum.com/t/syntax-problem/101672/7 "2006-08-07T12:11:33Z")

</div>

> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> –  
> Michael S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> [www.stellar-legends.de](http://www.stellar-legends.de) - Weltraum-Browsergame im Alpha-Stadium

No offence taken, thanks for the advice, found the book and started  
reading.

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [August 7, 2006, 12:12pm UTC](https://www.ruby-forum.com/t/syntax-problem/101672/8 "2006-08-07T12:12:21Z")

</div>

Mohit S. wrote:

> \<% end %\> ### this ends the iteration of book in @books…
> 
> Hope this helps,  
> Mohit

Thanks alot Mohit for your help, it worked.

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [August 7, 2006, 11:27am UTC](https://www.ruby-forum.com/t/syntax-problem/101672/9 "2006-08-07T11:27:15Z")

</div>

Guest wrote:

> > >
> 
> [CODE]
> 
> Data :confirm =\> 'Are you sure?', :post =\> true %\>
> 
> \<%= link\_to ‘Adauga Carte’, :action =\> ‘new’ %\>
> 
> [CODE]
> 
> I want to replace the “\<% for column in Book.content\_columns %\>
> 
> \<%=h  
> book.send(column.name) %\>” 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 %\>

\<%=h book.send(column.name) %\>  
\<% 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:

\<% for book in @books %\> ### This iterates over the books…

 ### replace the second iteration of "for column in Book.content\_columns" with -- ### this outputs the actual field.. ### this outputs the actual field.. ### this outputs the actual field.. .... ## \<% end %\> ### this ends the iteration of book in @books..

Hope this helps,  
Mohit

| Titlu | Subtitlu | Autor(i) | Editura | ISBN | Numar Inventar | URL Imagine | Data |
| --- | --- | --- | --- | --- | --- | --- | --- |
| \<%=h book.titlu %\> | \<%=h book.Subtitlu %\> | \<%=h book.Autor %\> |
