我的控制器出了问题。 我的参数评分未保存在我的列rating_score中。
我的控制器:
def rate
@konkurrancer = Konkurrancer.find(params[:id])
@container = "Konkurrancer"+@konkurrancer.id.to_s
@konkurrancer.rating_score += params[:rating].to_i
@konkurrancer.ratings += 1
@konkurrancer.save
respond_to do |format|
format.js
end
end
控制台日志:
Started POST "/konkurrancers/rate/51" for 127.0.0.1 at 2011-04-04 13:26:59 +0200
Processing by KonkurrancersController#rate as JS
Parameters: {"utf8"=>"Ô£ô", "authenticity_token"=>"v/u83R+w6WXIwqkjrHLZJxOby5/
tmOdzVGBPfBCLinI=", "vind"=>{"rating"=>"6"}, "commit"=>"Gem Vind", "id"=>"51"}
←[1m←[35mKonkurrancer Load (1.0ms)←[0m SELECT `konkurrancers`.* FROM `konkurr
ancers`
←[1m←[36mCACHE (0.0ms)←[0m ←[1mSELECT `konkurrancers`.* FROM `konkurrancers`←
[0m
←[1m←[35mCACHE (0.0ms)←[0m SELECT `konkurrancers`.* FROM `konkurrancers`
←[1m←[36mKonkurrancer Load (1.0ms)←[0m ←[1mSELECT `konkurrancers`.* FROM `kon
kurrancers` WHERE (`konkurrancers`.`cached_slug` = '51') LIMIT 1←[0m
←[1m←[35mSQL (1.0ms)←[0m SELECT sluggable_id FROM slugs WHERE ((slugs.sluggab
le_type = 'Konkurrancer' AND slugs.name = '51' AND slugs.sequence = 1))
←[1m←[36mKonkurrancer Load (0.0ms)←[0m ←[1mSELECT `konkurrancers`.* FROM `kon
kurrancers` WHERE (`konkurrancers`.`id` = 51) LIMIT 1←[0m
←[1m←[35mSQL (0.0ms)←[0m BEGIN
←[1m←[36mSlug Load (1.0ms)←[0m ←[1mSELECT `slugs`.* FROM `slugs` WHERE (`slug
s`.sluggable_id = 51 AND `slugs`.sluggable_type = 'Konkurrancer') ORDER BY id DE
SC LIMIT 1←[0m
←[1m←[35mAREL (2.0ms)←[0m UPDATE `konkurrancers` SET `ratings` = 4, `updated_
at` = '2011-04-04 11:27:00' WHERE (`konkurrancers`.`id` = 51)
←[1m←[36mSlug Load (3.0ms)←[0m ←[1mSELECT `slugs`.* FROM `slugs` WHERE (`slug
s`.sluggable_id = 51 AND `slugs`.sluggable_type = 'Konkurrancer') AND (`slugs`.`
name` = 'vind-et-rejsegavekort-på-helt-op-til-25000-kroner-lige-her') AND (`slu
gs`.`scope` IS NULL) ORDER BY id DESC←[0m
←[1m←[35mAREL (2.0ms)←[0m DELETE FROM `slugs` WHERE (`slugs`.`id` = 82)
←[1m←[36mSQL (1.0ms)←[0m ←[1mSELECT COUNT(*) FROM `slugs` WHERE (`slugs`.`nam
e` = 'vind-et-rejsegavekort-på-helt-op-til-25000-kroner-lige-her') AND (`slugs`
.`scope` IS NULL) AND (`slugs`.`sluggable_type` = 'Konkurrancer')←[0m
←[1m←[35mSQL (27.0ms)←[0m describe `slugs`
←[1m←[36mAREL (54.0ms)←[0m ←[1mINSERT INTO `slugs` (`name`, `sluggable_id`, `
sequence`, `sluggable_type`, `scope`, `created_at`) VALUES ('vind-et-rejsegaveko
rt-på-helt-op-til-25000-kroner-lige-her', 51, 1, 'Konkurrancer', NULL, '2011-04
-04 11:27:00')←[0m
←[1m←[35mSlug Load (1.0ms)←[0m SELECT `slugs`.* FROM `slugs` WHERE (`slugs`.s
luggable_id = 51 AND `slugs`.sluggable_type = 'Konkurrancer') ORDER BY id DESC L
IMIT 1
←[1m←[36mSQL (13.0ms)←[0m ←[1mCOMMIT←[0m
Rendered konkurrancers/_rating.html.erb (1.0ms)
Rendered konkurrancers/rate.js.erb (19.0ms)
Completed 200 OK in 417ms (Views: 183.0ms | ActiveRecord: 107.0ms)
答案 0 :(得分:2)
评级作为参数传递,格式如下:
params[:vind][:rating]
将控制器中的相关行从params[:rating]
更改为params[:vind][:rating]
,它应该可以正常工作。