I have a small app where the index page is a form that instructs the user for their email, I have changed my route so that the root_path is the ‘new’ action which renders my form:
Oa::Application.routes.draw do
resources :signups
match "/confirm", :to => "pages#confirm"
root :to => 'signups#new'
end
This is working fine, when I submit the form it is working fine. When I submit on the root page and I cause a validation error the address bar has the url localhost:3000/signups and shows me my validation errors, which is also good but if I were to manually visit http://localhost:3000/signups it gives me an error “The action ‘index’ could not be found for SignupsController”. Would it be ok if I created the ‘index’ action and redirect_to root_path so that I don’t receive the “The action ‘index’ could not be found for SignupsController” if I were to access http://localhost:3000/signups directly? Is this the proper way to do this?
class SignupsController < ApplicationController
def index
redirect_to root_path
end
def new
@signup = Signup.new
end
def create
@signup = Signup.new(params[:signup])
if @signup.save
UserMailer.registration_confirmation(@signup).deliver
flash[:notice] = "Signup created successfully."
redirect_to confirm_path
else
render :action => "new"
end
end
end
Thanks!
J
Do something like this:
Do not use
resources :signups