class Public::CommentsController < ApplicationController  

	def new
		@comment = Comment.new(:parent_id => params[:parent_id],:commentable_id => params[:commentable_id],:commentable_type => params[:commentable_type])

	end

	def create
		@comment = Comment.new(params.require(:comment).permit(:website, :pseudo, :email, :newsletter, :comment, :commentable_id, :commentable_type, :parent_id))
	
		

	
		if @comment.save
			
      
      if @comment.newsletter
        @registrant = Registrant.new(:email => @comment.email)
    		test = Registrant.find_by_email(@registrant.email)
    		if test and !test.enabled
    			@registrant = test
    			General.confirm_email(@registrant).deliver
    		else
		
    			if @registrant.save
    				General.confirm_email(@registrant).deliver
    			else
    				
    			end
    		end
        
      end
      
      
    else
      render :action => :new
		end

	end

end