0

I am using "friendly_id 4.0.0" gem for making url user friendly.

below is my user model

user.rb model

class User < ActiveRecord::Base
  extend FriendlyId
  friendly_id :name , :use => [:slugged,:history]
  attr_accessible :email, :lname, :name  
end

below is my user_controller.rb file

@user = User.new(params[:user])

respond_to do |format|
  if @user.save
    format.html { redirect_to @user, notice: 'User was successfully created.' }
    format.json { render json: @user, status: :created, location: @user }
  else
    format.html { render action: "new" }
    format.json { render json: @user.errors, status: :unprocessable_entity }
  end
end

But I am getting Can't mass-assign protected attributes: slug exception. I also try adding slug to attr_accessible as attr_accessible :email, :lname, :name, :slug But still getting same error.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user2534381
  • 215
  • 1
  • 3
  • 9

1 Answers1

0
attr_accessible :email, :lname, :name  

attr_accessible protect from mass-assignment

If you try something like following it will work

@user = User.new(params[:user])
@user.email = params[:user][:email]
respond_to do |format|
  if @user.save
Salil
  • 46,566
  • 21
  • 122
  • 156