【发布时间】:2012-11-02 20:39:22
【问题描述】:
我想向 Rails 应用程序添加一个路由,这样我就可以通过 id 以外的其他字段进行搜索(并且仍然可以通过 id 进行搜索)
def bycode
@plot = Plot.find_by_code(params[:code])
respond_to do |format|
if !plot.nil?
format.json {render json: @plot}
else
format.json
end
end
end
在 routes.rb 中:
resources :plots do
get 'bycode/:code' => 'plots#bycode'
end
在 $ rake 路线中我得到:
GET /plots/:plot_id/bycode/:code(.:format) plots#bycode
我只是希望能够做到
http://myapp.com/plots/bycode?code=codename
或类似的东西
我错过了什么?
【问题讨论】:
标签: ruby-on-rails routes