test
test

Reputation: 2466

How can I create a link_to with newly def

I set up new def like this:

  def info
    @book = Book.find(params[:id])
  end

and im trying to link it using this:

<%= link_to 'info', info_book_path %>

so the url should look like this localhost:3000/books/13/info (13 is an id of a book)

Any idea? thanks!

Upvotes: 0

Views: 28

Answers (1)

fotanus
fotanus

Reputation: 20116

On your routes you need to define the info path:

resources :books do
  member do
    get :info
  end
end

Then you will have the helper method

info_book_path(book)

More information on the railsguides

Upvotes: 1

Related Questions