Ich bin komplett neu auf Rails. Ich versuche es zu lernen, indem ich nach einem Video auf youtube ein Forum erstelle.Nicht definierte Methode 'Speichern' für Nil Rails
Allerdings stecke ich in einem Fehler und habe einfach keine Ahnung, wie man es löst. Ich erhalte „nicht definierte Methode 'Speichern' für null
Der Code.
-Controller
class PostsController < ApplicationController
def index
end
def new
@post = Post.new
end
def create
@post = Post.new[post_params]
if @post.save
flash[:success] = "Saved"
redirect_to action: :show
else
flash[:error] = "There was a problem adding"
render action: :new
end
end
def post_params
params[:post].permit(:title, :content)
end
new.html.haml
%h1 New post
= render 'form'
_form. html.haml
= simple_form_for @post do |f|
= f.input :title
= f.input :content
= f.submit
CreatePosts
class CreatePosts < ActiveRecord::Migration[5.1]
def change
create_table :posts do |t|
t.string :title
t.text :content
t.timestamps
end
end
end
Weiß jemand, was hier schief geht?
'@post = Post.new [post_params]' sollte '@post = Post.new (post_params)' – Gerry