weixin_33717117 2016-01-03 20:10 采纳率: 0%
浏览 5

Ajax在设计Rails中

I am currently doing a project, and I am using Devise for the User Authentication. I have the before_action :authenticate_user!in my Post Controller. When I click new post without Signing in it redirects to the Log in Page. That's fine, But I want it to be as pop over(when I click the new post,the log in form must popover). How can I achieve this. I have also referred to this

Rails 4 Devise Login as a POPUP window

But, still when I clicked the new Post, it is redirecting to the sign in page. Help me with this issue, Thanks in advance.

I have this code in my Users::SessionsController < Devise::SessionsController is

class Users::SessionsController < Devise::SessionsController


respond_to :json

  def create
    session['user_auth'] = params[:user]
    resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")

sign_in(resource_name, resource)
message = I18n.t 'devise.sessions.signed_in'

yield resource if block_given?

if request.xhr?
 return render :json => {:success => true, :login => true, :data =>  {:message => message}}
else
  respond_with resource, location: after_sign_in_path_for(resource)
end


end

  def failure
    user = User.where(email: session['user_auth'][:email]).first rescue nil
    message = I18n.t 'devise.failure.invalid', authentication_keys: "email"

respond_to do |format|
  format.json {
    render :json => {:success => false, :data => {:message => message, :cause => 'invalid'} }
  }
  format.html {
    redirect_to '/users/sign_in'
  }
end


end
end
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效