【问题标题】:ransack gem rails 3洗劫宝石铁轨 3
【发布时间】:2012-11-08 21:52:00
【问题描述】:

我在使用 gem ransack 时遇到了困难。我已经在我的 gemfile 中放置了 ransack,然后运行 ​​bundle install (虽然我只使用了 bundle,但这有什么不同吗?我认为没有?)

接下来我把它放在我的食谱控制器中

 def all_recipes
 @q = Recipe.search(params[:q])
 @searchresults = @q.result(:distinct => true)
 end

在我看来 (all_recipes) 我有搜索表单和块来显示我的结果

      <%= search_form_for @q do |f| %>
      <%= f.label :dish_name_cont %>
      <%= f.text_field :dish_name_cont %>
      <%= f.submit %>
      <% end %>
      ---------------------

      <% @searchresults.each do |r| %>
      <tr>
      <td><%= r.dish_name %></td>
      </tr>
      <% end %>

我遇到了两个问题,甚至没有进行搜索,我就在我看来这个块在哪里

fish and chips my first recipe lasagne Lasagne 

然后,如果我搜索说 las,它会在获取请求后将我重定向到我的索引页面,但由于我没有显示结果的块,我得到一个未定义的错误,这是预期的。

在此之后,我将控制器代码放在索引操作中,并将表单和块放在索引视图中,现在一切正常了吗?为什么我不能使用 all_recipes 操作,为什么它会重定向?

【问题讨论】:

    标签: ruby-on-rails-3 activerecord ransack


    【解决方案1】:

    深入演示,可能会有所帮助 - http://railscasts.com/episodes/370-ransack?view=asciicast

    【讨论】:

    • 看了这个 railscast 剧集,没有解释为什么我只能放在 index 动作中,除非我错过了什么?
    猜你喜欢
    • 1970-01-01
    • 2011-07-13
    • 2016-01-07
    • 1970-01-01
    • 2016-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-15
    相关资源
    最近更新 更多