【问题标题】:rails paperclip no direct access through sql query from another modelrails 回形针无法通过另一个模型的 sql 查询直接访问
【发布时间】:2013-11-03 19:22:40
【问题描述】:

如果尝试从另一个模型访问回形针图像以通过 sql 查询在其视图中显示,它将不会显示图像。

我在类别控制器中尝试了类似的操作,该控制器通过选择框在索引页面中从表单中获取参数。

category controller

def show

@category = Category.find_by_sql ["select distinct l.* from listings l , categories c, categories_listings cl where c.id = cl.category_id and l.id = cl.listing_id and c.id in (?,?)" ,  params[:c][:id1] , params[:c][:id2]]

end

在显示页面中,我无法从类别控制器访问列表模型中的回形针属性。

category show page      

<% @category.each do |c| %>

<%= c.place %>
<%= image_tag c.placeholder.url(:thumb) %>

<% end %>

listing和category有habtm关系

【问题讨论】:

    标签: sql ruby-on-rails activerecord paperclip


    【解决方案1】:

    这是一篇旧帖子,但我遇到了同样的问题,并且通过正确的查询和您已经拥有的相同循环很容易解决,但我的问题是在 Rails 4 中。

    对于以后遇到此问题的人,请尝试使用

    Category.where(:id => params[:id])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 2018-06-14
      • 1970-01-01
      相关资源
      最近更新 更多