I was using the tutorial on Getting Started with Rails http://tutorials.jumpstartlab.com/projects/blogger.html
I've already finished the tutorial, and now i'm using what i've done to create a site for a school work, i just want to add the "data" file on db/migrate/20161005160810_create_articles.rb, but i`m getting this message error
Showing /home/ubuntu/workspace/app/views/articles/show.html.erb where line #12 raised:
undefined method `data' for #<Article:0x007f8bcab2cfe8>
Extracted source (around line #12):
<p>
<strong>Data:</strong>
<%= @article.data %>
</p>
and my articles_controller is like this
class ArticlesController < ApplicationController
http_basic_authenticate_with name: "mateus", password: "mateus", except: [:index, :show]
def index
@articles = Article.all
end
def show
@article = Article.find(params[:id])
end
def new
@article = Article.new
end
def edit
@article = Article.find(params[:id])
end
def create
@article = Article.new(article_params)
if @article.save
redirect_to @article
else
render 'new'
end
end
def update
@article = Article.find(params[:id])
if @article.update(article_params)
redirect_to @article
else
render 'edit'
end
end
def destroy
@article = Article.find(params[:id])
@article.destroy
redirect_to articles_path
end
def article_params
params.require(:article).permit(:title, :text, :data)
end
end
Could someone help me?
Edit1: I used rake db:migrate:status
then i got this:
mateusjs:~/workspace (master) $ rake db:migrate:status
database: app_development
Status Migration ID Migration Name
--------------------------------------------------
up 20161005160810 Create articles
up 20161005185521 Create comments
up 20170209222858 Parte2
Does schema.rb
show that your Article
has a data
attribute?
A quick way to test this is to go into your console and
$ bundle exec rails console
> Article
And see if the data
is there.
If not, you might need to do two things;
$ bundle exec rails g migration AddDataToArticle data:integer
bundle exec rails db:migrate