新手问题 怎么在 route 中自定义 param

itsvoid · 2012年09月03日 · 最后由 itsvoid 回复于 2012年09月03日 · 2369 次阅读

我的一个脚手架 controller:mycontroller

match '/q/:query', :to => 'mycontroller#show'

我想在 show 方法中使用到 params[:query],但是 rails 报错,什么原因?

wrong number of arguments (1 for 0)

具体的错误信息是什么呢?

ArgumentError in CustomSearchEnginesController#show

wrong number of arguments (1 for 0) Rails.root: D:/startup/cse.so

Application Trace | Framework Trace | Full Trace actionpack (3.2.5) lib/action_controller/metal.rb:143:in params' app/controllers/custom_search_engines_controller.rb:18:inshow' actionpack (3.2.5) lib/action_controller/metal/implicit_render.rb:4:in send_action' actionpack (3.2.5) lib/abstract_controller/base.rb:167:inprocess_action' actionpack (3.2.5) lib/action_controller/metal/rendering.rb:10:in process_action' actionpack (3.2.5) lib/abstract_controller/callbacks.rb:18:inblock in process_action' activesupport (3.2.5) lib/active_support/callbacks.rb:414:in `run866169062process_action950889305_callbacks'

show 中的代码贴出来看一下。

找到问题了,params([:query]) 加了个括号···

需要 登录 后方可回复, 如果你还没有账号请 注册新账号