13
Jestem trochę zagubiony. Otrzymuję błąd Rails 4: ActiveModel :: ForbiddenAttributesError. Rozumiem, że oznacza to, że muszę zezwalać na przekazywanie przedmiotów, co zrobiłem, ale muszę czegoś przegapić.ActiveModel :: ForbiddenAttributesError - Rails 4
Komentarze Kontroler:
class CommentsController < ApplicationController
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.create!(params[:comment])
redirect_to @post
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def comment_params
params.require(:comment).permit(:post_id, :comment, :body)
end
end
Tworzenie Komentarze Migration
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.references :post
t.text :body
t.timestamps
end
end
def self.down
drop_table :comments
end
end
Co ja tu brakuje? Daj mi znać, jeśli potrzebujesz zobaczyć inny kod.
Dzięki!
Bla! Wiedziałem, że to musi być trywialne. Dzięki! –
Zadzwonił też do mnie z Rails 3, dzięki! – Zach