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.

4

1 回答 1

0
attr_accessible :email, :lname, :name  

attr_accessible防止大规模分配

如果您尝试以下操作,它将起作用

@user = User.new(params[:user])
@user.email = params[:user][:email]
respond_to do |format|
  if @user.save
于 2013-07-31T11:27:25.803 回答