strong parameters - Rails upgradation from 3.2.x to 4.0.3 with Ruby 2 -


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'. , trying make out it. can 1 please guide me model , controller code same.

remove attr_accessible models.

and in controller, lets take example of postscontroller, create private method post_params 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 updated.'         else             render "edit"         end     end      private      def post_params         params.require(:post).permit(:user_id, :description, :title)     end  end 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -