I wanted to create some static pages using rails and used
rails g controller Staticpages main movie song book
Which has created a controller file “static_pages_controller.erb” and
view files under /views/static_pages/main.html.erb etc
I have created a form using form_for on my main page which has a drop
down menu for selecting one of “movie, song, book” and a submit button
using
<%= form_for :mode do |f| %>
My controller file looks like this
class StaticPagesController < ApplicationController
def main
end
def movie
end
…
end
A click on submit on my main page generates 'No route matches POST
“/static_pages/main” . Do i have to create a func for post? If so since
the static pages class is same for the remaining movie,book, song how do
i handle submits from other pages?
Also how do i retrieve the values of form_for in the controller?
You’ll understand how to start and you’ll understand what you need to do
in
your controller and your routes.rb.
Le 22 juin 2012 23:05, “Arnaud Augier” [email protected] a crit
:
u need to do this form_for(:mode, :url => {:action => “action_name”,
:controller => “controller_name”})
and in the routes file, u need to add
post “static_pages/main” “contoller_name#action_name”
I can specify the controller using
:url => {:action => ‘XYZ’}
But since I don’t have ( nor need) a model file for the form , so what
should i write here “?”
<%= form_for (?) do |f| %>
If you have not got an object to populate the form then you can use
form_tag instead.
I can specify the controller using
:url => {:action => ‘XYZ’}
But since I don’t have ( nor need) a model file for the form , so what
should i write here “?”
<%= form_for (?) do |f| %>
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.