1

路线.rb

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

rails路线显示:

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>

那个帮手怎么了?

4

1 回答 1

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')
于 2012-05-12T23:13:17.223 回答