I’m new to ruby and started to create my *nd toy app. I:
- Created controller ‘questions’
- Created model ‘question’
- Created controller action ‘new’
- Added ‘New.html.erb’ file
in erb file I use form_for helper and and new controller action where I instantiate @question instance variable. When I try to run this I get 'undefined method: questions_path for #<ActionView::Base:0x5be5e24>' error. Below is my new.html.erb:
<%form_for @question do |f| %> <%=f.text_field :title %> <%end%>
Please advise how to fix this and also help me with aliasing this controller action. What I mean is I would like to type http://mysite/questions/ask, instead of /questions/create
In
config/routes.rbyou will need to add:to fix the undefined method questions_path problem.
One way to get
/questions/askis to modifyroutes.rblike so:which will give you
ask_question_pathwhich you can reference in your code.