0

I am following along a video series, where the author is creating a simple CMS using RoR 4, but I currently have RoR 3.x installed. I followed all the code to a "T" but when I try to create a simple subject in the simple CMS, I am getting an error. So I checked the log/production.log

And I am getting the following error, TypeError (no implicit conversion of Symbol into String):

The controller code looks like the following,

def create
    # Instantiate a new object using form parameters

    # the below line should work with rails v3.x
    # @subject = Subject.new(params[:subject])

    @subject = Subject.new(subject_params)

    # Save the object
    if @subject.save
      # add flash hash
      flash[:notice] = "Subject created successfully."
      # if save succeeds, redirect to the index action
      redirect_to(:action => 'index')
    else
      # if save fails, redisplay the form so user can fix problems
      render('new')
    end
  end

And the private method I created for the subject new params looks like the following

 private

    def subject_params
      # same as using "params[:subject]", except that it:
      # - raises an error if :subject is not present
      # - allows listed attributes to be mass-assigned
      params.require(:subject).permit(:name, :position, :visible)
    end
8
  • 2
    Please give more details about the error. Which file, what lines...etc? Commented Jun 3, 2014 at 1:59
  • we definitely need the full error with backtrace. Commented Jun 3, 2014 at 2:06
  • I'll ghostbin the subjects_controller.rb when I get home. Commented Jun 3, 2014 at 2:11
  • you've already posted the controller - we want the error. Commented Jun 3, 2014 at 2:11
  • @sevenseacat how would I get the full errror with backtrace? Commented Jun 3, 2014 at 2:12

1 Answer 1

3

The author tells you that you need to change @subject = Subject.new(subject_params) to @subject = Subject.new(params[:subject]).

params.require(:subject).permit(:name, :position, :visible) is a Rails 4 feature called Strong Parameters. If you are new to Rails I would suggest you use the version the author uses to alleviate future version issues like this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.