开发者

Troubleshooting empty params[] hash since Rails3 Upgrade

I have a named route that tests properly in the console and shows the :url_title which should be included in params[], yet params[] is always empty.

The question is, why is params[] empty? My expectation is it should have params[:url_title].

I also removed this route and used the default resource and params[] is still empty.

I've been checking params by using logger.

My app is an upgrade from Rails 2.3.5 to Rails 3.0.3.

Here's a code summary of what's going on.

# this is my route
match 'papers/:url_title' => 'papers#show', :as => :permalinkpaper

# this is link_to and the generated url being called
<%= link_to paper.title, paper_path(paper.url_title) %>
http://localhost:3000/papers/great-passion

# which properly matches to this controller#action for papers#show 
def show
    @paper = Paper.where(:url_title => params[:url_title]).first()
    PaperHistory.add( current_user, @paper.id )

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @paper }
      format.json { render :json => @paper }
      format.mobile # {开发者_如何学Python render :layout => false }
    end
  end

# which generals this error because the Paper looking returns noting because the params[:url_title] is nil
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

# the log stack trace
Started GET "/papers/great-passion" for 127.0.0.1 at Mon Jan 24 23:04:04 -0600 2011
  Processing by PapersController#show as HTML

  SQL (0.7ms)  SHOW TABLES
  SQL (0.5ms)  SHOW TABLES
  Paper Load (0.7ms)  SELECT `papers`.* FROM `papers` WHERE (`papers`.`url_title` IS NULL) ORDER BY title LIMIT 1
Completed   in 119ms

RuntimeError (Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id):
  app/controllers/papers_controller.rb:43:in `show'



# I've validated the route in the console and it seems to know :url_title is the proper value
>> r = ActionController::Routing::Routes
>> r.recognize_path "/papers/great-passion"
=> {:action=>"show", :url_title=>"great-passion", :controller=>"papers"} 

UPDATE: I have found that params[] are NOT empty when values are in the URL, such as when performing a search.

http://localhost:3000/papers?utf8=%E2%9C%93&keywords=passion

This successfully produces

Started GET "/papers?utf8=%E2%9C%93&keywords=passion" for 127.0.0.1 at Tue Jan 25 00:20:07 -0600 2011
  Processing by PapersController#index as HTML
  Parameters: {"utf8"=>"✓", "keywords"=>"passion"}
params: utf8✓keywordspassion


Thanks to all for the help. I was able to disassemble my app piece by piece and finally get params[] to show up.

The culprit was the open_id_authentication plugin.

I had some plugins in the vendors directory, so I removed them all and after hurdling a few resulting errors (b/c the plugins were now missing) everything worked. I systematically replaced plugins, and when I got to open_id_authentication found that the params[] again disappeared.


I had a different solution for this problem that I'll post here just in case somebody runs into the same issue. I was working on a password reset part of the site and tried various things such as putting the URL in manually, specifying the controller and action, using a bare (minimal) form and such, but all of it failed. The error given was the e-mail parameter was blank.

A look into the Exceptional logs showed that not just the e-mail parameter was blank, but even the UTF-8 check mark was missing. The only things in the params hash were the controller and action. Reloading the page also didn't turn up the usual spiel about re-submitting information.

It turns out the problem was in SSL. The page was trying to use SSL but didn't have permission and it was somehow silently killing the form. Hope that helps somebody.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜