Reputation: 307
I am getting a syntax error in my new.html.erb view. My code is:
<h1>Add new skill</h1>
<%= form_tag :action => 'create' %>
<p><label for="skill_title">Title</label>:
<%= text_field 'skill', 'title' %></p>
<%= collection_select :skill, :id, Skill.all, :id, :name %>
<%= submit_tag "Create" %>
<% end %>
<%= link_to 'Back', {:action => 'list'} %>
and my error is:
SyntaxError in SkillsController#new
app/views/skills/new.html.erb:10: syntax error, unexpected keyword_ensure, expecting end-of-input
It is pointing to the very last line of my code. Am I missing an end? I tried that and it did not work. Thank you anyone who can spot my error and hopefully it is a simple one.
app/views/skills/new.html.erb:2: syntax error, unexpected =>, expecting ')' ...r.append= form_tag (:action => 'create') do @output_buffer... ... ^ C:/HandCoOp/project/HandCoOp/app/views/skills/new.html.erb:2: syntax error, unexpected ')', expecting keyword_end ... form_tag (:action => 'create') do @output_buffer.safe_appe... ... ^ C:/HandCoOp/project/HandCoOp/app/views/skills/new.html.erb:10: syntax error, unexpected keyword_ensure, expecting end-of-input
Upvotes: 0
Views: 46
Reputation: 9173
If you look at your error it says:
SyntaxError in SkillsController#new
app/views/skills/new.html.erb:10: syntax error, unexpected keyword_ensure, expecting end-of-input
This type of error comes when you are trying to close a loop that's not opened.
Fix:
<h1>Add new skill</h1>
<%= form_tag :action => 'create' %>
<p><label for="skill_title">Title</label>:
<%= text_field 'skill', 'title' %></p>
<%= collection_select :skill, :id, Skill.all, :id, :name %>
<%= submit_tag "Create" %>
<% end %> # this is the culprit of your error
<%= link_to 'Back', {:action => 'list'} %>
But looking at your code it's a form so your end is supposed to be there but you forgot to open your loop:
<h1>Add new skill</h1>
<%= form_tag({action: "create"}) do %> #forgot this do to open your loop
<p><label for="skill_title">Title</label>:
<%= text_field 'skill', 'title' %></p>
<%= collection_select :skill, :id, Skill.all, :id, :name %>
<%= submit_tag "Create" %>
<% end %> # this is the culprit of your error
<%= link_to 'Back', {:action => 'list'} %>
Upvotes: 2
Reputation: 76784
To give you some clarity, @user2675613
pointed out the following:
<%= form_tag ({action: "create"}) do %>
<%= ... %>
<% end %>
According to the Rails docs, you've got to use do
at the end of the form_tag
declaration, in order to give Ruby a block
to work with.
If this does not work, I would look at how you're defining your route in the form_tag
declaration. You're currently just using an action
; I would use a path helper
to define the route correctly
--
Error
The issue you have is as follows:
unexpected keyword_ensure, expecting end-of-input
This basically means you're not calling end
on a block, or have created a code block
without defining the various arguments correctly. Using do
basically defines to Ruby that you'll be using a block, and will therefore look for an end
tag; which should be the fix you need
Update
In reference to your new error, it looks like it's asking you to include an )
somewhere. Looking at more Rails docs, I would say this is what you'll have to do:
<%= form_tag ({action: "create"}) do %>
EG
<%= form_tag({:action => 'create'}, {:id => 'anID'}) %>
Upvotes: 2