Ruby on rails Rails嵌套表单重定向问题
我正在创建一个注册过程如下的应用程序:Ruby on rails Rails嵌套表单重定向问题,ruby-on-rails,forms,redirect,nested,Ruby On Rails,Forms,Redirect,Nested,我正在创建一个注册过程如下的应用程序: 用户注册他们的公司(父帐户)并创建他们的 相同表单中的用户帐户(子帐户) 用户登录并为其他员工添加其他子帐户 每个公司帐户充当一个“包装器”,连接所有用户帐户 我已经完成了这项工作,但似乎无法在用户提交表单后将代码重定向回应用程序的根url。目前,它们正被转发到公司指数 谢谢 我的两款车型: class Company < ActiveRecord::Base attr_accessible :name, :address1, :address2
class Company < ActiveRecord::Base
attr_accessible :name, :address1, :address2, :city, :state, :zip, :users_attributes
has_many :projects, :dependent => :destroy
has_many :users, :dependent => :destroy
accepts_nested_attributes_for :users
end
class User < ActiveRecord::Base
authenticates_with_sorcery!
attr_accessible :email, :password, :password_confirmation, :first_name, :last_name, :created_on, :company_id
belongs_to :company
has_many :comments
has_many :tasks
validates_confirmation_of :password
validates_presence_of :password, :on => :create
validates_presence_of :email
validates_uniqueness_of :email
end
和表单
<%= simple_form_for(@company) do |f| %>
<%= f.error_notification %>
<%= f.simple_fields_for :users do |u| %>
<%= u.input :first_name %>
<%= u.input :last_name %>
<HR>
<%= u.input :email %>
<%= u.input :password %>
<%= u.input :password_confirmation %>
<% end %>
<div class="form-inputs">
<%= f.input :name %>
<%= f.input :address1 %>
<%= f.input :address2 %>
<%= f.input :city %>
<%= f.input :state %>
<%= f.input :zip %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
routes.rb中定义了什么
可能您忘记将其更改为您想要的根url只需重定向到“/”路径,而不是使用路由进行快速修复 公司控制人
def new
@company = Company.new
@company.users.build
end
def create
@company = Company.new(params[:company])
if @company.save
redirect_to root_url
else
render action: "new"
end
end
def new
@company = Company.new
@company.users.build
end
def create
@company = Company.new(params[:company])
if @company.save
redirect_to '/'
else
render action: "new"
end
end
root:to=>“projects#index”你能发布你所有的路由吗?FWIW,我把你的代码复制到一个测试应用程序中,它对我有效(将我作为根url路由回projects/index)。这就成功了!仍然想知道为什么我的路由被搞砸了,因为重定向到root_url在其他领域也起作用,但谁知道呢。谢谢
def new
@company = Company.new
@company.users.build
end
def create
@company = Company.new(params[:company])
if @company.save
redirect_to '/'
else
render action: "new"
end
end