Routing Rails 3 with string parameter
I'd like to be able to direct
/samplecontroller/search
with a :q parameter. How do I do this in rails 3? I currently have
match 'samplecontroller/:search' => 'samplecontroller#search'
but all it gives in rake:routes
/samplecontroller/:search(.:format) {:action=>"search", :controller=>"samplecontroller"}
The controller expects
def search
开发者_如何学C @search = Post.search(:include => [:comments]) do
keywords(params[:q])
end
end
Thanks!
Just do
match 'samplecontroller/search' => 'samplecontroller#search'
In routes.rb:
match 'samplecontroller/search' => 'samplecontroller#search'
Your version said that :search was a parameter for the route. Removing the leading colon tells it to match that whole string literally.
精彩评论