开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜