views:

341

answers:

2

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.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

+1  A: 

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 %>
Todd Yandell
Hi Todd,Thanks a stack. It worked as you said. Funny the book does not have it like that, must be an older version of rails.G
Gigg
A: 

Hi Todd/Gigg, I noticed that you removed the apostrophes from the create action of the form tag. When I do this, I receive a undefined local variable or methodcreate' for #`

With the apostrophes, the error is:

undefined local variable or method `action' for #<ActionView::Base:0x1036f1d60>

Any ideas? Thanks in advance

McCully
Try putting quotes around `create` in the `form_tag` line.
theIV
Thanks theIV. Figured it out. Rookie mistake, missed a colon on action. Working fine now. Cheers
McCully