I have seem this question posted before but the normal "add :content to model" doesn't work for my situation. I have already added it and the error still occurs.
This a modified version of a codecademy project if it looks familiar.
Model
class CreateNotes < ActiveRecord::Migration
def change
create_table :notes do |t|
t.text :content
t.timestamps
end
end
end
Controller
class NotesController < ApplicationController
def index
@notes = Note.all
end
def new
@note = Note.new
end
def create
@note = Note.new(note_params)
if @note.save
redirect_to '/notes'
else
render 'new'
end
end
private
def note_params
params.require(:note).permit(:content)
end
end
Route
Rails.application.routes.draw do
root 'notes#index'
get "notes" => "notes#index"
get "notes/new" => "notes#new"
post "notes" => "notes#create"
index.html.erb
<div class="header">
<div class="container">
<h1>Notes</h1>
</div>
</div>
<div class="notes">
<div class="container">
<% @notes.each do |note| %>
<div class="note">
<p class="content"><%= note.content %></p>
<p class="time"><%= note.created_at %></p>
</div>
<% end %>
<%= link_to 'New Note', "notes/new" %>
</div>
</div>
new.html.erb
<div class="header">
<div class="container">
<h1>Notes</h1>
</div>
</div>
<div class="create">
<div class="container">
<%= form_for(@note) do |f| %>
<div class="field">
<%= f.label :note %><br>
<%= f.text_area :content %>
</div>
<div class="actions">
<%= f.submit "Create" %>
</div>
<% end %>
</div>
</div>
If anyone can figure out why I am still getting this error after :content is already in the model, that would be awesome!
P.S. First post so sorry if it is terrible.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire