奥基斯·伊夫进行了广泛深入的探索,找到了我可以找到的解决办法。
我有2个模式
http://www.ohchr.org。
class Store < ActiveRecord::Base
attr_accessible :storeimage, :storename
belongs_to :user
validates :user_id, :presence => true
end
以及
www.un.org/spanish/ecosoc 用户<>
class User < ActiveRecord::Base
attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :userimage, :remove_userimage
has_secure_password
has_many :gears
has_many :comments, :dependent => :destroy
has_one :store, :dependent => :destroy
before_save :create_remember_token
require carrierwave/orm/activerecord
mount_uploader :userimage, UserpicUploader
accepts_nested_attributes_for :store
...
end
当有人创建新的用户账户时,我需要自动为该用户建立一个新的仓库,我是在用户表中思考的。 因此,我如何能够创建与新用户连接的新储存物体?
下面是我从发出的守则。 创建行动用户主计长
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
redirect_to @user, :flash => {:success => "Welcome to Equiptme"}
else
render new
@title = "Sign up"
end
end
<div class="signup_container">
<div class="signup_container_interior">
<%= provide(:title, Sign up ) %>
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div>
<div>
The form contains <%= pluralize(@user.errors.count, "error") %>.
</div>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="register_field">
<div class="register_nonerror_container">
<%= f.label :first_name %> <%= f.text_field :first_name, class: register_text_area %>
</div>
</div>
<div class="register_field">
<div class="register_nonerror_container">
<%= f.label :last_name %> <%= f.text_field :last_name, class: register_text_area %>
</div>
</div>
<div class="register_field">
<div class="register_nonerror_container">
<%= f.label :email %> <%= f.text_field :email, class: register_text_area %>
</div>
</div>
<!--************STORE FIELDS ************** -->
<!--************STORE FIELDS END ************** -->
<div class="register_field">
<div class="register_nonerror_container">
<%= f.label :password %> <%= f.password_field :password, class: register_text_area %>
</div>
</div>
<div class="register_field">
<div class="register_nonerror_container">
<%= f.label :password_confirmation %> <%= f.password_field :password_confirmation, class: register_text_area %>
</div>
</div>
<div class="actions">
<%= f.submit "Create Account", class: register_button %>
</div>
<% end %>
</div>
</div>