我正在使用注册过程创建应用程序,如下所示:
- 用户注册他们的公司(父帐户)并以相同的形式创建他们的用户帐户(子帐户)。
- 用户登录并为其他员工添加其他子帐户。
每个公司帐户都充当连接所有用户帐户的“包装器”。
我已经完成了这项工作,但似乎无法在用户提交表单后将代码重定向回应用程序的根 url。目前,它们正被转发到公司指数。
谢谢!
我的两个模型:
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
公司控制人
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
和形式
<%= 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 %>
编辑:
我的路线
resources :password_reset
get "logout" => "sessions#destroy", :as => "logout"
get "login" => "sessions#new", :as => "login"
get "adduser" => "users#new", :as => "adduser"
resources :users
resources :sessions
resources :companies
get "signup" => "companies#new", :as => "signup"
resources :comments
root :to => "projects#index"
resources :tasks do
member do
get :change
end
end
resources :phases
resources :projects