IvanH
IvanH

Reputation: 45

Undefined method in controller (Routing)

I'm new at rails and I'm currently working on an already existing application that handles butons like so:

<%= link_to 'Edit', edit_answer_path(ans) %>

That links to the file /answers/edit.html.erb but now I need to make a button that links to the file /answers/comment.html.erb how do I go about doing this?

I already tried with

<%= link_to 'Comment', comment_answer_path(ans) %>

but I get the error "Undefined method 'comment_answer_path'" even after adding this lines to answers_controller :

def comment
  ans = Answer.find(params[:id])
end

Upvotes: 1

Views: 111

Answers (2)

Ho Man
Ho Man

Reputation: 2345

It depends on how you've set up the routes in routes.rb.

You can use rake routes to see the list of all paths and their alias.

Upvotes: 1

Simple Lime
Simple Lime

Reputation: 11035

You need to add a route to your config/routes.rb and then restart the server. Something like

resources :answers do
  member do
    get 'comment'
  end
end

will create the comment_answer_path helper for you as well.

Upvotes: 2

Related Questions