I'm new to ruby and started to create my *nd toy app. I:
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.rb
you will need to add:
map.resources :questions
to fix the undefined method questions_path problem.
One way to get /questions/ask
is to modify routes.rb
like so:
map.ask_question '/questions/ask', :controller => 'questions', :action => 'create'
which will give you ask_question_path
which you can reference in your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With