0

models/user.rb

class User < ActiveRecord::Base
   attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :login
end

models/post.rb

class Post < ActiveRecord::Base
  has_many :comments, dependent: :destroy
  belongs_to :user

  attr_accessible :user_id, :description, :title
end

models/comment.rb

class Comment < ActiveRecord::Base
  belongs_to :post
  belongs_to :user

  attr_accessible :body, :user_id
end

I have installed 'strong_parameters'. And trying to make out with it. Can any one please guide me for model and controller code for the same.

user3067558
  • 93
  • 1
  • 8

1 Answers1

0

Remove attr_accessible from models.

And in the controller, lets take the example of PostsController, create a private method post_params where you will define accessible attributes of Post model

class PostsController < ApplicationController

    def update
        @post = Post.find(params[:id])
        if @post.update(post_params)
            redirect_to @post, notice: 'Post was successfully updated.'
        else
            render "edit"
        end
    end

    private

    def post_params
        params.require(:post).permit(:user_id, :description, :title)
    end

end
Ishank Gupta
  • 1,575
  • 1
  • 14
  • 19