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