Ian Steffy
Ian Steffy

Reputation: 1234

NoMethodError in PostsController#create undefined method `text' for #<Post:0x007f99088407f8>

I've been having trouble getting past this error. It says that it 'text' is undefined.

class PostsController < ApplicationController
  before_action :set_post, only: [:show, :edit, :update, :destroy]

  def create
    @post = Post.new(post_params)
      respond_to do |format|
        if @post.save # (this line is highlighted in the error)
          format.html { redirect_to @post, notice: 'Post was successfully created.' }
          format.json { render action: 'show', status: :created, location: @post }
        else
          format.html { render action: 'new' }
          format.json { render json: @post.errors, status: :unprocessable_entity }
        end
      end
  end

This worked fine when I had originally 'rails generate' the scaffold with title:string body:text.

I've been stuck on this problem all day. Suggestions would be awesome.

Upvotes: 0

Views: 844

Answers (1)

usha
usha

Reputation: 29349

Your view is accessing the attribute text, but it should be body

Upvotes: 1

Related Questions