简体   繁体   中英

Rails 3 Metasearch issue, but only in production

I must be doing something wrong. I have a simple search that works fine in development (with sqlite3 DB) but not in production (with MYSQL DB). Not sure how to debug.

Here are the details:

Controller:

def index
  @search = Individual.search(params[:search])
  @individuals = @search.all
  # @individuals = @search.order(:lastname).page params[:page]
end

View:

= form_for @search, :url => individuals_path, :html => {:method => :get} do |f|
  %fieldset
    %strong
      = f.label :firstname_like, "First Name?"
    = f.text_field :firstname_like
    %strong
      = f.label :lastname_like, "Last Name?"
    = f.text_field :lastname_like
    = f.submit "Search"

No problems using the console in the production environment:

Individual.search :lastname_like => 'Smith', :firstname_like => ''
=> #<MetaSearch::Searches::Individual:0blahblah....

Just doesn't work via the browser. I get EVERY Individual returned. (No errors)

I'm wondering if it's something to do with URL encoding?

Started GET "/individuals/?utf8=%25E2%259C%2593&search%255Bfirstname_like%255D=& search%255Blastname_like%255D=hermans&commit=Search" for 68.87.23.92 at Thu May 26 09:22:31 -0700 2011
  Processing by IndividualsController#index as HTML
  Parameters: {"commit"=>"Search", "search%5Bfirstname_like%5D"=>"", "utf8"=>"%E2%9C%93", "search%5Blastname_like%5D"=>"smith"}

Any ideas? Or at least how to debug?

Rails 3.0.7 Metasearch 1.0.3

If you are getting the output on console, then your function is working correctly. To debug try logging information at every step and see where it goes wrong, eg print the params being passed to search function, what output is search returning, etc etc and see where thing go wierd. You can also look at the db query being fired in production.log and try running it manually from the terminal and see the result.

You can even try running your application in development mode on the production server, changing the database.yml to use the production db and mysql to see if it is an environment specific issue.

Yeah, I'd say it's something with the url. As far as I can tell it should look like this:

/individuals/?utf8=%E2%9C%93&search%5Bfirstname_like%5D=&search%5Blastname_like%5D=hermans&commit=Search

I don't use haml, so I can't say what's going on but it's a problem with your form. It's adding those '25's in every encoded character. Is the encoding set correctly on your page?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM