I know there are question with this title, but none of them solved my problem.So, i want to do this in the application.html.erb
<% @food_types.each do |ft| %>
<%= ft.name %>
<%end%>
And i have this in my application_controller.rb
@food_types = FoodType.all
Here is the migration for the FoodTypes table.
class CreateFoodTypes < ActiveRecord::Migration
def change
create_table :food_types do |t|
t.string :name
t.timestamps null: false
end
end
end
What should i do for this error ? undefined method `each' for nil:NilClass
default application controller
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception
@food_types = FoodType.all
end
Aucun commentaire:
Enregistrer un commentaire