开发者

Ruby on Rails: how do you specify an html ID with the form_tag

I'm using the form tag, and I want the result to be nomething like this:

<form action="controller/action" id="myID">

I currently have this

<% form_tag :action => '', :id=>"relative_date_filter" do |f| %>

which generates this:

<form action="/controller/relative_date_filter" method="post">

EDIT:

I currently get this error:

compile error
/app/views/controller/filters/_relative_time.html.erb:1: syntax error, unexpected tASSOC, expecting '}'
...e=true ;  form_tag {:action => ''}, {:id => "relative_date_f...
                              ^
/app/views/controller/filters/_relative_time.html.erb:1: syntax error, unexpected ',', expecting kEND
...e ;  form_tag {:action => ''}, {:id => "relative_date_filter...
                              ^
/app/views/controller/filters/_relative_time.html.erb:1: syntax error, unexpected kDO, expecting kEND
... => "relative_date_filter"} do ; @output_buffer.concat "\n  ...
                              ^
/app/views/controller/filters/_relative_time.html.erb:14: syntax error, unexpected kENSURE, expecting $end
Extracted source (around line #1):

1: <% form_tag {:action => ''}, {:id => "relative_date_filter"} do %>

Here, what is weird is that there is no line 14. its the end of the file.开发者_StackOverflow I added a return, and it changed to line 15. My previous code did cause the syntax error.


This should work:

<% form_tag({:action => ''}, {:id => "relative_date_filter"}) do |f| %>


The first parameter of form_tag is the url which is why you're seeing 'relative_date_filter' used for that. I think the extra options may allow you to specify an id.

<% form_tag({:action => ''}, {:id => 'relative_date_filter'}) do |f| %>

The first hash being the url and the second any extra options. This is also where the form method is supplied if you want anything other than post, for example.


<%= form_tag ({:controller => 'public', :action => 'search'}), ({:class => "round_corners_8"}) do %>

This one is working for me in Rails 3.0

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜