Forum: Ruby on Rails Problem with helper form_tag syntax

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
andi (Guest)
on 2005-11-25 13:03
(Received via mailing list)

the Rails book says i can use something like this in my view

   <%= form_tag :action => :new, {:class => 'more'}  %>

This gives an syntax error, whereas only this (ugly looking) works:

   <%= form_tag( {:action => :new} , {:class => 'more'} ) %>

some ruby syntax stuff i get wrong here?

brad (Guest)
on 2005-11-25 17:22
(Received via mailing list)
AFAIK, Ruby collects any hash parameters at the *end* of the argument
list into a hash. So,

<%= form_tag {:action => :new}, :class => 'more' %>

may work. On the other hand, IIRC, it is considered deprecated to
omit the parentheses on functions in views now. You would probably
get a warning on the above. So the 'minimalist' correct ERb code
would probably look like this:

<%= form_tag( {action => :new}, :class => 'more' ) %>

Brad E.
andi (Guest)
on 2005-11-25 21:21
(Received via mailing list)
Hey Brad,

thanks for clarifying this.

This topic is locked and can not be replied to.