Created
January 25, 2011 04:44
-
-
Save davidortinau/794524 to your computer and use it in GitHub Desktop.
My Rails3 Routing Issue - params are empty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is my route | |
match 'papers/:url_title' => 'papers#show', :as => :permalinkpaper | |
# this is the url being called | |
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 # { 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"} | |
# I'm at a loss! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment