0

I'm pretty new to Ruby on Rails and i'm trying to build a simple blogging platform that allows user authentication using devise. When I fill out the posts form which takes a title and content field, when I press the "create post" button i get an error that reads

SystemStackError in PostsController#create stack level too deep

It seems as if the "create" action in my PostsController is where the problem stems from. Can any one help me? This is how my PostsController looks:

class PostsController < ApplicationController

    before_action :authenticate_user! 

    def index
      @posts = Post.all 
    end 

    def new 
      @post = Post.new
    end 

    def create
      @post = Post.new(params[:post])
    end 

    def show 
      @post = Post.find(params[:id])
    end 

    private 

    def params
      params.require(:post).permit(:title, :content)
    end


end
shivam
  • 16,048
  • 3
  • 56
  • 71
NdaJunior
  • 374
  • 3
  • 17

1 Answers1

5

Easy, you call params method in the body of params method (recursively) - boom, infinite loop. Change the name of your custom params method:

def create
  @post = Post.new(post_params)
  # etc.
end

# ...

def post_params
  params.require(:post).permit(:title, :content)
end
Marek Lipka
  • 50,622
  • 7
  • 87
  • 91