Question

I have a question about a form in a one page application... I would like to do kind of:

  root 'static#index', :via => :post

but of course it doesn't work. I have a form in a one page application and would like to redirect to the same page after the submit done.

This is my controller:

def index
   @message = Message.new
end

def create
  @message = Message.new(params[:message])

  if @message.valid?
    NotificationsMailer.new_message(@message).deliver
    redirect_to(root_path, :notice => "Message")
  else
    flash.now.alert = "Errors ..."
    render :index
  end
end

and my form:

= simple_form_for @message, :url => root_url do |f|
....
= f.button :submit, value: "Send Message"

The error I get is:

No route matches [POST] "/"

Thanks for help and advices.

Was it helpful?

Solution

I think this should work:

post "/" => "static#create"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top