Questions tagged [attr-accessible]

attr-accessible creates a white-list of editable attributes

attr-accessible is reference of Ruby on Rails new "attr_accessible" feature. It lets programmers define a white-list of attributes that can be modified by a user through its user interface.

104 questions
3
votes
3 answers

Is there a way to set attr_accessible by default in a rails project with Mongoid?

The recommended solution is this: config.active_record.whitelist_attributes = true But this only works if you are using active record. On a mongoid rails project is there a similar approach? It uses active model but not active record.
Brian Armstrong
  • 19,149
  • 14
  • 109
  • 140
3
votes
1 answer

Calling accessor methods from within a Model object in Rails

I have the following method in my model def reset_review_status needs_review = true save end There is an attribute on the model called needs_review, however when I debug it, it saves it as a new variable. If I do self.needs_review=true, it…
Dave G
  • 4,306
  • 4
  • 22
  • 27
3
votes
1 answer

undefined method `attr_accessible' with Mongoid

I am using Rails 4.1.1, ruby 2.1, mongodb, mongoid as a wrapper, rails_admin for creating admin interfaces I know that 'attr_accessible' no longer works for Rails4. So i have installed 'protected_attributes' gem. But still no success i am still…
prashantsahni
  • 1,949
  • 18
  • 19
3
votes
0 answers

accessing class_attribute from module in Rails 4

I have a module that defines custom attr_accessible attribute as follow: module MyModule include ActiveModel::MassAssignmentSecurity %w[var1 var2].each do |key| attr_accessible key end end class MyClass include…
AdamNYC
  • 17,771
  • 28
  • 90
  • 147
3
votes
1 answer

Mongoid attr_accessible not working

Today morning I wake with this weird issue where mongoid was creating a record for the attributes which isn't being defined in the model To overcome this i decide to implement attr_accessible also mention in Mongoid specification "Providing a…
Viren
  • 5,764
  • 6
  • 35
  • 91
3
votes
1 answer

How to properly pass an array of values to the `attr_accessible` method?

I am using Ruby on Rails v3.2.2 and I would like to handle an array of symbols so to pass its values to the attr_accessible method as well as it should be made. That is, I have: attr_array = [:one, :two, ...] If I use: attr_accessible attr_array I…
user12882
  • 4,216
  • 9
  • 35
  • 53
2
votes
2 answers

Is there any tutorial for Rails 3.2 that covers assigning an admin attribute to a user?

Disclaimer: I'm using Rails 3.2. Specifically, in the Rails 3 in Action book: The User model does have attr_accessible attr_accessible :email, :password, password_confirmation, :remember_me The User model NOT have :admin listed, therefore it can't…
Joe C
  • 1,223
  • 1
  • 10
  • 23
2
votes
2 answers

Respond_with using Devise & attr_accessible in Rails 3

I'm building an API with Rails 3, using devise to handle some of the authentication. I commonly use the respond_with method to return xml/json for various resources. Eg GET /groups.xml will route to def index respond_with Group.all end This…
tomblomfield
  • 839
  • 1
  • 8
  • 11
2
votes
2 answers

Using attr_accessible in a join model with has_many :through relationship

I have a USER that creates a COMPANY and become an EMPLOYEE in the process. The employees table has an :user_id and a :company_id. class User has_many :employees has_many :companies, :through => :employees class Employee belongs_to :user belongs_to…
2
votes
1 answer

Is this caused by attr_accessible?

I just lately update my model with attr_accessible fields and suddenly some tests would not work, as i would expect. However, i have a spec like: context "when user buys a game item" do let(:inventory) {@user.inventory << Factory(:inventory)} …
Spyros
  • 41,000
  • 23
  • 80
  • 121
2
votes
1 answer

Bug? I've to mass-assign params two times to update has_many association

I've a Register model which has_many :telephones Register model accepts_nested_attributes_for :telephones, :reject_if number and code blank?, and has attr_accessible :telephones_attributes (and all other fields) Telephones belongs_to :register and…
2
votes
3 answers

mongoid, set_table_name & attr_accessible

I'm using rails3 edge and mongoid 2beta6 with ruby 1.9.2-head. How can I manually change the table name, just like set_table_name for ActiveRecord? For example my model Signup should use the table "users" for storage, not "signups". Another…
gucki
  • 4,250
  • 7
  • 37
  • 53
2
votes
1 answer

how override attr_accessible role ActsAsTaggableOn::Tag model?

how override attr_accessible role for field :name in Tag model in ActsAsTaggableOn gem ? I want some things like that in Tag model ... attr_accessible :name, :as => [:default, :admin] for allow me to edit field name of tag by admin role
2
votes
2 answers

Unable to add custom fields to my Devise user model in Rails 4 with strong parameters

I've tried everything I can find, including what is in the Devise README (https://github.com/plataformatec/devise#strong-parameters), this more descriptive take on the README…
2
votes
1 answer

How should I protect mass-assignment in Sinatra app with Datamapper?

I have Link model in Sinatra app class Link include DataMapper::Resource has n, :views validates_presence_of :url, message: "You must specify a URL." validates_length_of :url, maximum: 4096, allow_blank: true, message:…
tomekfranek
  • 7,110
  • 7
  • 41
  • 74