【发布时间】:2012-12-18 18:35:56
【问题描述】:
不知道为什么我能解决这个问题,但希望能得到一些帮助。在使用 ransack 显示搜索结果时,我试图从我的用户模型中访问属性名称。
我的配方控制器是这样的
def index
@q = Recipe.search(params[:q])
@searchresults = @q.result(:distinct => true)
@q.build_condition
end
def search
index
end
所以当我在搜索页面中输出结果时,我可以从配方模型中选择属性,但无法从用户模型返回任何内容(我想这与我的索引中有 Recipe.search 的事实有关? )
查看
<% @searchresults.each do |r| %>
<%= image_tag r.avatar.url(:thumb)%>
<%= r.user.name%>
<%= r.dish_name %>
<%= r.difficulty %>
<%= r.preperation_time %>
<% end %>
我得到了未定义的方法名称
配方模型
belongs_to :user
用户模型
has_many :recipes
我错过了什么,我猜的很简单?
谢谢
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 object associations