0

I am writing a new app and used an old app as kind of a reference on how to do things I am creating the new page and using the form_for

<% form_for(store) do |f| %>

<% end %>


def new
  @store = Store.new
end

Above is my controller did it the same way I did in my last app and getting this error. I am getting this error that is puzzling me because it works on other applications I made.

undefined local variable or method `store' for #<#<Class:0x007fb26b3634c0>:0x007fb26a427ce0>
Did you mean?  @store

I must be missing something conceptually.

3 Answers 3

5

You created variable @store, that's why ruby doesn't know what is store

<% form_for(@store) do |f| %>

You should read error messages

undefined local variable or method `store' ... Did you mean? @store

Sign up to request clarification or add additional context in comments.

Comments

1

I think you're missing something simple...

there was a change in the recent version of rails that passes a local variable to the partial that contains the form_for... and in doing so, removes the need for the @ symbol in the partial view. You can fix your error by adding an @ symbol before the store in the form for, or by creating the "translation" of the global variable to the local one... (excuse the terminology, i'm self taught).

<%= render 'form', store: @store %>

2 Comments

So I must not be using the same versions of rails?
you are using examples that were generated by different versions of rails, that have a subtle difference... it doesn't really have to do with being different versions though, just a new "normal" way to do it...
0

Use @store in view.

<% form_for(@store) do |f| %>

<% end %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.