Ruby (Ruby on Rails) is creating a restaurant word-of-mouth site like a food log while referring to tutorials.I set categories for each area, but I failed to pull them from the controller on the search results.
NoMethodError in Restaurants
undefined method `restaurant'
·Research results (restaurants/search.rb)
<%@search_restaurants.each do |restaurant|%>
<span><%=space.area.name%></span>
<%end%>
·Controllers (restaurants_controllers.rb)
def search
@restaurants=Restaurant.paginate (page:params[:page])
@category=Category.all
end
·Routing (routes.rb)
resources:categories, param::category_name do
resources:restaurants, only: [:show]
end
I put in @category and found re/restaurants/1 」 in text.
I'm sorry, but I appreciate your cooperation.
ruby-on-rails ruby mvc
I set the view as below and it was resolved.
<%=restaurant.category.try(:name)%>
It seems that the problem was that there were no categories in the database.
© 2024 OneMinuteCode. All rights reserved.