gpt4 book ai didi

sql - Ruby on Rails 保存到数据库

转载 作者:太空宇宙 更新时间:2023-11-03 17:23:27 25 4
gpt4 key购买 nike

嗨,我是 Ruby on Rails 的初学者这是我的疑问。我的 Controller 中有这个方法

def save_profile
p "======================================"
p params
p "======================================"
p params[:company][:job_locations_attributes]
p "company_params------------------------"
p company_params
p "--------------------------------------"
company_profile
@location = JobLocation.new(:city_id => params[:city_id])
@location.save
if @company.update_attributes(company_params)
redirect_to company_dashboard_path(@company.id)
else
render 'company_profile'
end
end

在终端我得到类似的输出

"======================================"
{"utf8"=>"✓", "authenticity_token"=>"kbId4JgeaM+mGlmZC1U4gFCUYN7LHmuqWq8Es3rxa+k=", "company"=>{"name"=>"Besole", "address"=>"<p>Besole, Besole, Besole, Besole</p>", "employee_count"=>"> 200", "company_type"=>"Business", "foundation_year"=>"2020", "mission"=>"Besolification", "website"=>"https://www.besole.com", "facebook_page_url"=>"https://www.facebook.com/besole", "twitter_page_url"=>"https://www.twitter.com/besole", "description"=>"Besole besole Besole Besole Besole Besole besole", "delete_logo"=>"", "logo_crop_x"=>"", "logo_crop_y"=>"", "logo_crop_h"=>"", "logo_crop_w"=>"", "jobs_attributes"=>{"33"=>{"id"=>"33", "company_id"=>"11", "title"=>"Besoler", "description"=>"<p>besoler besoler besoler</p>", "job_type_id"=>"1", "experience"=>"1 - 3 Years", "job_category_id"=>"2", "skill_ids"=>["", "6", "5", "7", "9", "11", "12", "16", "15"], "_destroy"=>"false"}}, "job_locations_attributes"=>{"33"=>{"job_locations"=>"2"}}}, "city_id"=>"40035", "portfolios_id"=>"321", "commit"=>"Submit", "controller"=>"companies", "action"=>"save_profile", "id"=>"11"}
"======================================"
{"33"=>{"job_locations"=>"2"}}
"company_params------------------------"
{"name"=>"Besole", "logo_crop_h"=>"", "logo_crop_w"=>"", "logo_crop_x"=>"", "logo_crop_y"=>"", "delete_logo"=>"", "address"=>"<p>Besole, Besole, Besole, Besole</p>", "employee_count"=>"> 200", "company_type"=>"Business", "mission"=>"Besolification", "website"=>"https://www.besole.com", "description"=>"Besole besole Besole Besole Besole Besole besole", "foundation_year"=>"2020", "facebook_page_url"=>"https://www.facebook.com/besole", "twitter_page_url"=>"https://www.twitter.com/besole", "jobs_attributes"=>{"33"=>{"id"=>"33", "company_id"=>"11", "title"=>"Besoler", "description"=>"<p>besoler besoler besoler</p>", "job_type_id"=>"1", "experience"=>"1 - 3 Years", "job_category_id"=>"2", "skill_ids"=>["", "6", "5", "7", "9", "11", "12", "16", "15"], "_destroy"=>"false"}}}
"--------------------------------------"

我想得到 33 和工作地点..我想将这两个变量保存在 job_id 和 state_id 列下的表 Location 中,其中 job_id 为 33,state_id 为 2

最佳答案

你可以使用它。

job_id = params[:company][:job_locations_attributes].keys[0] 

state_id = params[:company][:job_locations_attributes][job_id]['job_locations']

关于sql - Ruby on Rails 保存到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22525345/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com