开发者

Simple search in ruby on rails

开发者 https://www.devze.com 2023-03-04 07:13 出处:网络
I\'m trying to do a pretty simple search. I have a search action in my controller: def search @tracker = Tracker.where(params[:search])

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

精彩评论

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