【发布时间】:2012-01-14 14:53:52
【问题描述】:
我有一个小应用程序,其中的索引页面是指示用户发送电子邮件的表单,我更改了路线,以便 root_path 是呈现我的表单的“新”操作:
Oa::Application.routes.draw do
resources :signups
match "/confirm", :to => "pages#confirm"
root :to => 'signups#new'
end
这工作正常,当我提交表单时它工作正常。当我在根页面上提交并导致验证错误时,地址栏有 url localhost:3000/signups 并显示我的验证错误,这也很好,但如果我要手动访问 http://localhost:3000/signups 它会给我一个错误“找不到 SignupsController 的操作‘索引’”。如果我创建了 'index' 操作和 redirect_to root_path 以便在我直接访问 http://localhost:3000/signups 时不会收到“找不到 SignupsController 的操作 'index'”,是否可以?这是正确的方法吗?
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
谢谢!
J
【问题讨论】:
标签: ruby-on-rails