I am creating a blogging application which uses active_admin
for admin panel. When I try to comment on a post it is redirecting me to active_admin
login page.
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
So the reason you have been redirected to login page is you have not logged in yet.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.