hi im new in ROR development and starting a reservation system project
i am to show the menu that the customer added in the package that he
choose and inside that menu the recipes of the current menu but it rises
me a
undefined method ‘menu’ error
i belive my associations of my model is right but you may correct it if
its wrong thank
package_line_item.rb
belongs_to :menu
belongs_to :reservation
reservation.rb
has_one :reservation_package
belongs_to :service
has_many :reservation_function_rooms
has_many :package_line_items
has_many :menus , :through => :package_line_items, :uniq => true
has_many :function_rooms, :through =>:reservation_function_rooms
menu.rb
has_many :package_line_items
has_many :menu_recipes
has_many :recipes, :through => :menu_recipes, :uniq => true
belongs_to :menu_category
package_line_item_controller.rb
def index
@package_line_items = PackageLineItems.all
end
def show
@reservation = Reservation.includes(:package_line_items =>
:menu).find(params[:id])
end
def new
@reservation = Reservation.find(params[:reservation_id])
@package_line_item = @reservation.package_line_items.build
end
def create
@reservation = Reservation.find(params[:reservation_id])
@reservation.package_line_items.build(params[:package_line_item])
if @package_line_item.save
redirect_to @reservation ,:notice => "added menu"
end
routes.rb
resources :services
resources :reservations do
resources :reservation_packages
resources :reservation_function_rooms
resources :packages
resources :package_line_items
resources :package_crews
end
resources :function_rooms
resources :crews
resources :menu_categories
resources :menus do
resources :menu_recipes
end
ActiveAdmin.routes(self)
devise_for :admin_users, ActiveAdmin::Devise.config
resources :recipe_categories
resources :recipes
package_line_item/show.html.erb
<%= notice %>
<%= @reservation.package_line_items.menu.name%>
i tried on my show.html.erb file
<%= @reservation.package_line_items.first.menu.name%>
but it only returns the first menu that i added the when i open the
second menu the information inside it is the the information in my first
menu
if other file is needed feel free to ask me thank you more power to us
thanks