嗨,我想知道是否有一種方式,用戶可以更新他們已經寫的評論,我試着使用康康,但遇到了一些問題,所以我寧願找出是否有一個更容易辦法。這是從審查控制器在Ruby on Rails中更新用戶評論
def new
if logged_in?
@review = Review.new(:film_id => params[:id], :name =>
User.find(session[:user_id]).name)
session[:return_to] = nil
else
session[:return_to] = request.url
redirect_to login_path, alert: "You must be logged in to write a review"
end
end
「新」方法和「創造」的方法
def create
# use the class method 'new' with the parameter 'review', populated
# with values from a form
@review = Review.new(params[:review])
# attempt to save to the database, the new review instance variable
if @review.save
# use the class method 'find' with the id of the product of the
# saved review and assign this product object to the variable 'product'
film = Film.find(@review.film.id)
# redirect the reviewer to the show page of the product they reviewed,
# using the product variable, and send a notice indicating the review
# was successfully added
redirect_to film, notice: "Your review was successfully added"
else
# if the review could not be saved, return/render the new form
render action: "new"
end
end
我希望用戶,如果他們已經寫評論的編輯審查代碼產品。而不是從同一用戶對同一產品進行兩次評論。
輝煌!非常感謝 – 2013-02-24 15:18:11