简体   繁体   中英

Ruby on rails “undefined method” error

When I try to run the following code on a form I get the following error message:

 undefined method `store_ID' for # <Store:0x007f98ec2a1d68> 

I checked the model, controller, and schema but the store_ID is consistent with the other working parameters. How do I "define" it first?

<%= simple_form_for(@store) do |f| %>
    <%= f.error_notification %>
    <%= f.error_notification message: f.object.errors[:base].to_sentence
        if f.object.errors[:base].present? %>

    <div class="form-inputs">
        <%= f.input :location, required: true %>
        <%= f.input :branch_manager, required: true %>
        <%= f.input :store_ID, required: true %>
    </div>

    <div class="form-actions">
        <%= f.button :submit %>
    </div>
<% end %>

Here are my schema.rb

create_table "stores", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| 
    t.string "location" 
    t.string "branch_manager" 
    t.integer "store_ID" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
end

I think you have not run the migrations according to what you say

"I added the ID field after generating everything, so I do not know if that makes the difference"

With this you should solve:

rails db:migrate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM