99miles
99miles

Reputation: 11232

Rails routing - url helper results in 'undefined method'

routes.rb

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

rails routes shows:

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

Then I use a helper:

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

Which results in

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

What's wrong with that helper?

Upvotes: 1

Views: 2469

Answers (1)

Siwei
Siwei

Reputation: 21617

your code works fine for me in Rails 3.2

here are the key code:

# 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')

Upvotes: 1

Related Questions