the browser returned me the following error in Locals#show:
undefined method 'model_name' for NilClass:Class
51: <%= form_for(@food) do |f| %>
52: <%= render 'shared/error_messages', object: f.object %>
53: <div class="field">
54: <%= f.label :nome %>
Here is my locals_controller.rb (the show action)
def show
@local = Local.find(params[:id])
@foods = @local.foods.paginate(page: params[:page])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @local }
end
end
And here foods_controller.rb (the create action)
def create
@food = @local.foods.build(params[:food])
if @food.save
flash[:success] = "Food created!"
redirect_to '/locals'
else
flash[:error] = "Error on creating food"
render '/locals'
end
end
Food model and Local model are related with :has_many and belongs_to
What's the issue? Thank you
Check by adding following code (I assumed that your model is Local)@food = Local.new
In your new action
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With