我想在客户端控制器的视图中从以下链接传递参数并且哈希是@client,我想传递@client.user_id,如果我输入(:id => @client.user_id)我无法获取:id 在我要传递此参数的另一个控制器 Estate 中。我应该怎么办 ?有没有办法做到这一点?(两个控制器是 Client 和 Estate,我想将参数从 Client 视图传递给 Estate 控制器的 create 方法。这里没有资源嵌套!)
<%= link_to "New Property", new_estate_path(:key => @client.first.user_id) %>
创建动作
def create
# @estate = Estate.new(params[:estate])
if current_user.Company.nil?
@estate = current_user.estates.build(params[:estate])
else
serve = User.find(params[:key])
debugger
@estate = serve.estates.build(params[:estate])
#@estate.user_id = user_id
debugger
end
respond_to do |format|
if @estate.save
if @estate.Mgmt.nil?
EstateMailer.company_confirmation(@estate).deliver
end
format.html { redirect_to @estate, notice: 'Estate was successfully created.' }
format.json { render json: @estate, status: :created, location: @estate }
else
format.html { render action: "new" }
format.json { render json: @estate.errors, status: :unprocessable_entity }
end
end
end