farhad rubel
farhad rubel

Reputation: 2374

Rails 'Method not found' in form_for f.text_field

I've added a new column using following command:

rails g migration AddMatrixPositionToAnswer matrix_position:integer

then ran the command:

rake db:migrate

Now if I write the following code to my view, I get Method not found

<%= f.number_field :matrix_position, :class => 'form-control' %>

error is:

Method not found

Update:

Migration file: enter image description here

Database Schema: enter image description here

Form:

<%= form_for(@answer) do |f| %>


  <div class="field">
    <%= f.label :matrix_position %><br>
    <%= f.text_field :matrix_position %>
  </div>
  <div class="field">
    <%= f.label :value %><br>
    <%= f.text_field :value, :class => 'form-control', :Placeholder => 'Any value (e.g. M (Male), F (Female), United States (US))' %>
  </div>
  <%= f.hidden_field :question_id %>

  <div class="actions">
  <%= f.submit(:value => ' Save', :class => 'fa btn btn-success' ) %>
<hr />

  </div>
<% end %>

Interestingly, <%= f.label :matrix_position %> works. But <%= f.text_field :matrix_position %> doesn't work.

Upvotes: 1

Views: 259

Answers (1)

K M Rakibul Islam
K M Rakibul Islam

Reputation: 34338

You actually have a TYPO in your database table's column. See carefully: martix_position in the database. But, you are specifying matrix_position in the f.text_field, that's why it's failing :)

So, either change database column to matrix_position with another migration. Or, use: f.text_field :martix_position in the form, your choice :-)

Upvotes: 1

Related Questions