开发者

Problem with converting form_tag in rails

I am new to ruby and rails and I am having a problem from Beggining Ruby on Rails Ecommerce. (Yes, it's an old book).

I have these 2 code sets for a view:

new.html.erb:

<%= form_tag :action=> 'create' do -%>
<%= render :partial => 'form' %>
 <%= submit_tag 'Create' %>
 <%= end -%>

<% link_to 'Back', :action => 'index' %>

_form.html开发者_StackOverflow中文版.erb:

<% error_messages_for 'supplier' %>

<p><label for="supplier_first_name">First Name</label><br/>
<%= text_field 'supplier', 'first_name' %></p>

<p><label for="supplier_last_name">Last Name</label><br/>
<%= text_field 'supplier', 'last_name' %></p>

But It wont show although I added the do option. It keeps giving me this error:

C:/rails/emporium/app/views/admin/supplier/new.html.erb:1: syntax error, unexpected ')'
...orm_tag :action=> 'create' do ).to_s)
...                               ^
C:/rails/emporium/app/views/admin/supplier/new.html.erb:4: syntax error, unexpected keyword_end
; @output_buffer.concat(( end ).to_s)
                             ^
C:/rails/emporium/app/views/admin/supplier/new.html.erb:5: syntax error, unexpected tIVAR, expecting ')'
@output_buffer.concat "\n"
              ^
C:/rails/emporium/app/views/admin/supplier/new.html.erb:7: syntax error, unexpected keyword_ensure, expecting keyword_end
C:/rails/emporium/app/views/admin/supplier/new.html.erb:9: syntax error, unexpected $end, expecting ')'

Can anyone suggest how I fix this since I have not found a google answer yet.

Thanks

Gigg


It looks like you have <%= %> and <% %> mixed up in several places. You need to use <% %> with form_tag, and <%= %> with link_to and error_messages_for. The latter two methods return their output, while form_tag automatically appends its output to the output buffer (which is generally true for any helper that accepts a block).

Try this:

new.html.erb:

<% form_tag :action => create do %>
<%= render :partial => "form" %>
<%= submit_tag "Create" %>
<% end %>

<%= link_to "Back", :action => "index" %>

_form.html.erb:

<%= error_messages_for :supplier %>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜