【发布时间】:2011-06-16 19:53:50
【问题描述】:
我遇到的问题是 company_id 没有保存到详细信息表中 我知道 company_id 在那里我在添加所有公司详细信息之前使用表单上的 检查它,但由于某种原因,除了 company_id 之外,我保存了其他所有内容
##user.rb
has_one :company
##company.rb
belongs_to :user
has_one :detail
##detail.rb
belongs_to :user
##details controller
def new
@detail = Detail.new
user_id = session[:user_id]
company_id = params[:id]
end
def create
@detail = Detail.new(params[:detail])
@detail.user_id = session[:user_id]
@detail.company_id = params[:id]
end
###settings.html.erb
### this is where i make sure that company_id gets pass with the url
link_to 'New Detail', {:controller => 'details', :action =>'new', :id => company.id }, :class => 'plus'
#####routes
resources :details
resources :companies
resources :users
resources :sessions
如果您知道更好的方法,我知道这可能看起来不漂亮或不合适,请告诉我...提前致谢。
【问题讨论】:
-
请发布您的新方法呈现的表单。
标签: ruby-on-rails-3 routing foreign-keys models nested