开发者

Simple search in ruby on rails

I'm trying to do a pretty simple search. I have a search action in my controller:

def search
      @tracker = Tracker.where(params[:search])
  end

And, in my view:

<%= form_tag trackers_search_path, :method => 'get' do %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>
  </p>
<% end %>

But, it's still returning nil values. Here's the log:

Parameters: {开发者_如何转开发"utf8"=>"✓", "id"=>"search", "search"=>"1Xc9fc0e"}
  Tracker Load (0.2ms)  SELECT "trackers".* FROM "trackers" WHERE ("trackers"."token" = 'search') LIMIT 1

Seems to me, it's not passing the right param into the select statement, but I'm not sure why.


It looks like the routing might be messed up? Are you sure the search action is actually being called? It looks like it's going to show with id search. Try adding a debugger call or a Rails.logger.debug call to see what action is being called. Or just look at the entire log entry.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜