-3

I am trying to submit a test post through my form, and I am getting this error: param is missing or the value is empty: content. I am requiring "content" and permitting a "title". Both fields were filled out when submitting the post or "thought" in my app. I believe the problem has something to do with strong parameters. I can't find the answer anywhere else on the internet. Here is my controller.

class ThoughtsController < ApplicationController
  def index

  end

  def new
    @thought = Thought.new(params[:id])
  end

  def create
    @thought = Thought.new(params[post_params])

    @thought.save

    if @thought.save
        redirect_to @thought 
    else
        render :new
    end
  end


  private
  def post_params
    params.require(:content).permit(:title)
  end

end

Thanks for the help.

tomcruise
  • 17
  • 1
  • 7
  • Please start read about rails first. You are having too many problem in your controller. New method does not take any parameter also you are creating new object with id params. Your strong parameter also not defined in correct way. `post_params` can not be used in such way `params[post_params]` in create method. – Dipak Gupta Aug 28 '14 at 06:55
  • What were the submitted parameters? (You'll find them in the log file) – Frederick Cheung Aug 28 '14 at 06:56
  • just content and title I believe – tomcruise Aug 28 '14 at 07:07

1 Answers1

0

The following should work. You propably understand the strong_parameters a bit wrong. If your thought object has :content and :title attributes, they should be listed in permit parenthesis - this will mean you allow their mass-assignment.

def create
  @thought = Thought.new(post_params)

    if @thought.save
      redirect_to @post 
    else
      render :new
    end
  end


    private
    def post_params
      params.require(:thought).permit(:content, :title)
    end
Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145