我有这个应用程序,用户可以在其中为学校写评论。用户必须使用 Facebook 登录才能保存评论。
问题:
如果用户未签名并写了评论,然后用 facebook 登录,他们必须再次写相同的评论。
我想更像这样处理它:unsigned user write a review, signs in with facebook and then the review is saved. But right now the user writes a review and then signs in and nothing is saved, the user have to write the review all over again
.`
怎么能做到这一点?任何想法或解决方案都会很棒!
审核表:
<%= form_for [@school, Review.new] do |f| %>
<%= f.text_area :content %>
<% if current_user %>
<%= f.submit 'Save my review', :class => "btn" %>
<% else %>
<%= f.submit 'Save my review and sign me into facebook', :class => "btn" %>
<% end %>
<%end %>
评论控制器:
class ReviewsController < ApplicationController
before_filter :signed_in_user, only: [:create, :destroy]
def create
@school = School.find(params[:school_id])
@review = @school.reviews.new(params[:review])
@review.user_id = current_user.id
if @review.save
redirect_to @review.school, notice: "Review has been created."
else
render :new
end
end
def new
@school = School.find_by_id(params[:school_id])
@review = Review.new
end
private
def signed_in?
!current_user.nil?
end
def signed_in_user
unless signed_in?
redirect_to "/auth/facebook"
end
end
end