开发者

RoR: ending form_tag compile error

What is the correct way to use the form tag, I am getting a compile error when I include the end. When I take it out it works, should I just manually end the form with HTML? Or is there something wrong with my syntax?

   <html>
  开发者_JAVA技巧   <head>
      <title>
      Databse connections
      </title>
     </head>
     <body>
      <%= form_tag ( :action => 'create' )%>
       <%= text_field(:album, :title) %>
       <%= text_field(:album, :artist) %>
       <%= text_field(:album, :genre) %>
       <%= datetime_select(:album, :release_date) %>
       <%= submit_tag("Create") %>  
      <% end %>

     </body>
    </html>


If you use form_tag without a block, it'll only create the opening tag. If you want to create both tags, you need to pass it a block, which you appear to be trying to do, but you are missing the do keyword after form_tag(...):

<% form_tag ( :action => 'create' ) do %>
  <%= text_field(:album, :title) %>
  <%= text_field(:album, :artist) %>
  <%= text_field(:album, :genre) %>
  <%= datetime_select(:album, :release_date) %>
  <%= submit_tag("Create") %>  
<% end %>

Without do to start the block, the end is a syntax error. Without the end in your current syntax, you are not specifying that the fields are to be within the form (but they will end up being part of your form because you aren't closing your form tag created by the block-less form_tag before specifying them).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜