Rails路由 - url helper导致'undefined method'

时间:2012-05-12 22:26:37

标签: ruby-on-rails ruby-on-rails-3

的routes.rb

  match 'mybookings/:token' => 'mybookings#test', :as => 'bookit'
  resources :mybookings

rails routes显示:

bookit /app/mybookings/:token(.:format) mybookings#test

然后我使用帮手:

=link_to "by clicking here", bookit_url(@client.token)

结果是

ActionView::Template::Error
Error
undefined method `bookit_url' for #<#<Class:0x007fd2c1ca3488>:0x007fd2c1f96960>

那个助手有什么问题?

1 个答案:

答案 0 :(得分:1)

你的代码在我的Rails 3.2中运行良好

这是关键代码:

# in routes.rb
match 'mybookings/:token' => 'mybookings#test', :as => 'bookit'

# in controller:
class MybookingsController
  def test
    render :text => 'this is bookit action'
  end
end

# in your erb or haml file:
link_to "by clicking here", bookit_url('this is the token string')