John Smith
John Smith

Reputation: 6269

Form post to controller#action

In my adminpage#index controller i have defined @software:

if Software.first != nil
      @software = Software.first
        else
      @software = Software.new
end 

Then in my form i have:

  <% form_for(@software), :url => adminpage_setting_path do |f| %>
  <%= f.label 'Name der zugelassenen Software' %>
  <%= f.text_field :software %><br>
  <%= f.label 'Software-Relase' %>
  <%= f.text_field :release %><br>
  <%= f.label 'Softwareverantwortlicher' %>
  <%= f.text_field :sv %><br>
  <% end %>

Somehow this invokes an error:

  syntax error, unexpected ',', expecting keyword_end
 ';  form_for(@software), :url => adminpage_setting_pa...
                         ^

I really have no clue what i made wrong! Thanks

Upvotes: 0

Views: 34

Answers (2)

Andrew Wei
Andrew Wei

Reputation: 2100

Replace:

<% form_for(@software), :url => adminpage_setting_path do |f| %>

With:

<%= form_for @software, :url => adminpage_setting_path do |f| %>

EDIT:

Mini explanation as per requested by: Helios de Guerra

  1. :url is a parameter of form_for as sevenseacat mentioned
  2. I'm assuming you want the < form > element tag to be printed. Therefore you should use <%= %> vs. just <% %>

Upvotes: 1

sevenseacat
sevenseacat

Reputation: 25049

the :url => adminpage_setting_path is actually the second parameter to the form_for method.

It should be form_for(@software, :url => adminpage_setting_path) do |f|.

Upvotes: 2

Related Questions