嗨,我想知道是否有一种方式,用户可以更新他们已经写的评论,我试着使用康康,但遇到了一些问题,所以我宁愿找出是否有一个更容易办法。这是从审查控制器在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