0

我正在创建一个active_admin用于管理面板的博客应用程序。当我尝试对帖子发表评论时,它会将我重定向到active_admin登录页面。

评论型号:-

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

活跃的管理员评论模型:-

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

end

职位控制器:-

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

评论控制器:-

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

评论表:-

<%= 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 %>

当我单击添加评论按钮时,它会将我带到活动的管理员登录页面。有人可以帮我吗?

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
4

1 回答 1

0

看这里:before_filter :auth_user

所以你被重定向到登录页面的原因是你还没有登录。

于 2013-04-17T14:36:23.690 回答