Undefined Method In Rails
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
config/routes.rb you will need to add:
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.
- → Trigger a click with jQuery using link_to of rails 4
- → Adding html data attribute to simple_forms input
- → How to remove parameters from the root URL if it does I18n
- → passing parameters to rails back end from an ajax call
- → Blocking ?page= in robots.txt
- → react js and rails Updating state on a component with active record relationship
- → State not passed into prop
- → Cannot read property 'modalIsOpen' of undefined
- → Objects not valid issue
- → How to map API params to model
- → Consuming webhooks shopify-api
- → How to add ScriptTag on shopify_api gem?