简体   繁体   English

Rails博客添加评论重定向到活动管理员登录页面

[英]rails blog add comment redirecting to active admin login page

I am creating a blogging application which uses active_admin for admin panel. 我正在创建一个使用active_admin作为管理面板的博客应用程序。 When I try to comment on a post it is redirecting me to active_admin login page. 当我尝试对帖子发表评论时,它会将我重定向到active_admin登录页面。

Comment Model:- 评论模型:

class Comment < ActiveRecord::Base
  belongs_to :user
  belongs_to :post, :counter_cache => true
  attr_accessible :text, :user_id, :post_id

  validate :text, :presence => true
end

Active Admin Comment Model:- 活动管理员评论模型:-

ActiveAdmin.register Comment, :as => "PostComment" do

end

Posts Controller:- 帖子管理员:-

def show
    @post = Post.find(params[:id])
    @showPost = true
    respond_with do |format|
      format.html # show.html.erb
      format.json { render json: @post }
    end
end

Comments Controller:- 评论控制器:

class CommentsController < ApplicationController
    before_filter :auth_user

   def create
     @post = Post.find(params[:post_id])
     params[:comment][:user_id] = current_user.id
     @comment = @post.comments.create(params[:comment])
     redirect_to post_path(@post)
   end
end

Comment Form:- 评论表格:-

<%= semantic_form_for ([@post, @post.comments.build]), :html => { :id => "comment-form", :class => "metta-form"} do |f| %>
    <h5 class="pull-left">Comments</h5>
  <div class="clearfix">
  </div>
    <div class="wrap-comment-form">
        <%= f.inputs do %>
            <%= f.input :text, :label => false, :input_html => { :class => "comment-text pull-left" } %>
        <% end %>
        <%= f.actions do %>
            <%= f.action :submit, :label => "Add Comment", :button_html => { :placeholder => "Enter Your Comment Here", :class => "btn btn-primary btn-metta pull-right" } %>
        <% end %>
    </div>
<% end %>

When I click on the add comment button it takes me to active admin login page. 当我单击添加评论按钮时,它将带我进入活动的管理员登录页面。 Can someone help me out here ?? 有人可以在这里帮我吗?

class ApplicationController < ActionController::Base
  protect_from_forgery

  helper ApplicationHelper

  def after_sign_in_path_for(resource) 
    '/users/home'
    end
  def after_sign_up_path_for(resource)
    '/users/home'
  end
  def auth_user
    redirect_to new_user_path unless user_signed_in?
  end
end

Look here: before_filter :auth_user 看这里: before_filter :auth_user

So the reason you have been redirected to login page is you have not logged in yet. 因此,您被重定向到登录页面的原因是您尚未登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM