…
private
def post_params
params.require(:post).permit(:title, :body)
end
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :body
t.integer :user_id
t.timestamps
end
end
end
comments_controller.rb
…
private
def comment_params
params.require(:comment).permit(:body)
end
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.integer :body
t.integer :post_id
t.integer :user_id
t.timestamps
end
end
end
…
private
def post_params
params.require(:post).permit(:title, :body)
end
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :body
t.integer :user_id
t.timestamps
end
end
end
comments_controller.rb
…
private
def comment_params
params.require(:comment).permit(:body)
end
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.integer :body
t.integer :post_id
t.integer :user_id
t.timestamps
end
end
end
thank you
воскресенье, 30 ноября 2014 г., 11:47:19 UTC-8 пользователь Vivek
Sampara
написал:
…
private
def post_params
params.require(:post).permit(:title, :body)
end
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :body
t.integer :user_id
t.timestamps
end
end
end
comments_controller.rb
…
private
def comment_params
params.require(:comment).permit(:body)
end
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.integer :body
t.integer :post_id
t.integer :user_id
t.timestamps
end
end
end
thank you
воскресенье, 30 ноября 2014 г., 11:47:19 UTC-8 пользователь Vivek
Sampara
написал:
I would recommend a different solution. You should not rely on an form
to
capture the user_id, unless the user is actually selectable from a
dropdown. Yes, you could put the user_id in a hidden form field;
however,
that leaves it open to be changed by the user.