这将是一个很难提供意见的问题,所以我会尽可能详细地提供。以下是我试图弄清楚的确切问题。出于某种原因,当我保存时,经验是删除列中的所有其他值并在更新当天写入。我刚刚保存了所有其他值,但为了清楚起见,我将它们排除在表之外。最奇怪的部分是预算和经验设置完全相同,但不幸的是并没有节省相同的费用。下面是关于这个问题的更多细节。
非常感谢您对可能发生的事情的任何见解。
+------+--------+-----------+------------+-----------------+
| id | bar_id | day | budget | experience |
+------+--------+-----------+------------+-----------------+
| 1816 | 369 | monday | LOW BUDGET | |
| 1817 | 369 | tuesday | low budget | |
| 1818 | 369 | wednesday | low budget | IN CONVERSATION |
| 1819 | 369 | thursday | low budget | |
| 1820 | 369 | friday | low budget | |
| 1821 | 369 | saturday | low budget | |
+------+--------+-----------+------------+-----------------+
+------+--------+-----------+------------+--------------------+
| id | bar_id | day | budget | experience |
+------+--------+-----------+------------+--------------------+
| 1822 | 369 | monday | LOW BUDGET | |
| 1823 | 369 | tuesday | low budget | |
| 1824 | 369 | wednesday | low budget | |
| 1825 | 369 | thursday | low budget | ON THE DANCE FLOOR |
| 1826 | 369 | friday | low budget | |
| 1827 | 369 | saturday | low budget | |
+------+--------+-----------+------------+--------------------+
这些是表单(视图)的输入
<div class="row clearfix">
<div class="label">Budget</div>
<div class="mid budget">
<div class="mid">
<input class="venProfileInputs caps" name="bar_profile[<%= day %>][budget]" onblur=checkBudVals(this)>
</div>
</div>
</div>
<div class="row clearfix">
<div class="label">Experience</div>
<div class=" mid">
<input class="venProfileInputs caps" name="bar_profile[<%= day %>][experience]" onblur=checkExVals(this) />
</div>
</div>
然后进入控制器
def update
@bar = Bar.find(params[:id])
if @bar.update_attributes(params[:bar])
@bar.update_profiles(params[:bar_profile])
redirect_to "/admin", :notice => "Bar was successfully updated."
else
render :action => :edit
end
end
它在模型中得到更新
def update_profiles(params)
profiles.each {|p| p.destroy }
params[:active_profiles].split(',').each do |profile_day|
next if profile_day.blank?
add_profile(params[profile_day.to_sym])
# sets up crowd tags
crowd_tags_ids = params[profile_day.to_sym][:tags]
unless crowd_tags_ids.blank?
crowd_tags_ids.split(',').each do |tag_id|
next if tag_id.strip == ""
profiles.last.crowd_tags << CrowdTag.find(tag_id)
end
end
profiles.last.set_crowd_tags
#need to loop through cf_tags_ids = params[profile_day.to_sym][:cf_tags]
cf_tags_ids = params[profile_day.to_sym][:cf_tags]
unless cf_tags_ids.blank?
# loop through each category 0,1,2,3,4
cf_tags_ids.each_pair{ |cat, ids|
#cycle through each id in the current cat and add to crowd fiter tag
ids.split(',').each do |cf_id|
next if cf_id.strip == ""
profiles.last.crowd_filter_tags << CrowdFilterTag.find(cf_id)
end
}
end
profiles.last.set_cf_tags
# below is not working for saving experience
profiles.last.experience = params[profile_day.to_sym][:experience]
logger.info "#{profiles.last.inspect}"
#### Still need to save experience some how, budget seems to be getting saved
# but only one value for experience is being logged in a single row for each bar_id
end
end
记录器输出:
Parameters: {"utf8"=>"✓",
"bar"=>{"name"=>"Rue B", "website"=>"www.ruebnyc.com", "neighbourhood"=>"Greenwich Village",
"street_address"=>"188 Avenue B", "city"=>"New York", "country"=>"US", "state"=>"NY", "zipcode"=>"10009"},
"bar_profile"=>{"active_profiles"=>",monday,tuesday,wednesday,thursday,friday,saturday",
"monday"=>{"day"=>"monday", "description"=>"", "plan_b"=>"", "capacity"=>"100",
"rating"=>"5", "budget"=>"LOW BUDGET", "experience"=>"ON THE DANCE FLOOR",
"cf_tags"=>{"0"=>"83,", "1"=>"127,", "2"=>"120,", "3"=>"111,", "4"=>"128,"}, "tags"=>"16,46,45,"},
"tuesday"=>{"day"=>"tuesday", "description"=>"Come after dining hours to mellow out with the Lost Generation of today. Fedora optional.",
"plan_b"=>"", "capacity"=>"", "rating"=>"0", "budget"=>"low budget", "experience"=>"",
"cf_tags"=>{"0"=>"61,", "1"=>"", "2"=>"", "3"=>"", "4"=>""}, "tags"=>""},
"wednesday"=>{"day"=>"wednesday", "description"=>"Come after dining hours to mellow out with the Lost Generation of today. Fedora optional.",
"plan_b"=>"", "capacity"=>"", "rating"=>"0", "budget"=>"low budget", "experience"=>"",
"cf_tags"=>{"0"=>"61,", "1"=>"", "2"=>"", "3"=>"", "4"=>""}, "tags"=>""},
"thursday"=>{"day"=>"thursday", "description"=>"Come after dining hours to mellow out with the Lost Generation of today. Fedora optional.",
"plan_b"=>"", "capacity"=>"", "rating"=>"0", "budget"=>"low budget", "experience"=>"",
"cf_tags"=>{"0"=>"59,", "1"=>"", "2"=>"", "3"=>"", "4"=>""}, "tags"=>""},
"friday"=>{"day"=>"friday", "description"=>"Come after dining hours to mellow out with the Lost Generation of today. Fedora optional.",
"plan_b"=>"", "capacity"=>"", "rating"=>"0", "budget"=>"low budget", "experience"=>"",
"cf_tags"=>{"0"=>"60,", "1"=>"", "2"=>"", "3"=>"", "4"=>""}, "tags"=>""},
"saturday"=>{"day"=>"saturday", "description"=>"Come after dining hours to mellow out with the Lost Generation of today. Fedora optional.",
"plan_b"=>"", "capacity"=>"", "rating"=>"0", "budget"=>"low budget", "experience"=>"",
"cf_tags"=>{"0"=>"59,", "1"=>"", "2"=>"", "3"=>"", "4"=>""}, "tags"=>""},
"sunday"=>{"day"=>"sunday", "description"=>"", "plan_b"=>"", "capacity"=>"", "rating"=>"",
"budget"=>"", "experience"=>"", "cf_tags"=>{"0"=>"", "1"=>"", "2"=>"", "3"=>"", "4"=>""}, "tags"=>""}}, "id"=>"369"}