GithubHelp home page GithubHelp logo

safe_attributes's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

safe_attributes's Issues

Interferes with Devise validations

From google searching it appears someone ran into an issue using safe_attributes and devise together due to another validation somewhere expecting the generated attribute methods to exist. Steps to reproduce were given as use both gems in a project.

Does not prevent problems with certain keywords or weird names

While a great idea, this does not help with for example database columns named 'changed' (because a changed? method will be generated, triggering a DangerousAttributeError) or 'reply-to' (because the dash will cause things to explode).

Possibly it needs to hook in deeper, to prevent the creation of any methods at all for these columns.

safe_attributes breaks password and password_confirmation fields for Devise objects

We have a User class in our Rails project that uses Devise for authentication. The password and password_confirmation fields in devise, by default, work a little differently.

In short, those fields conflict with the override of #read_attribute_for_validation.

Rather than focusing on fixing this directly, my vote is that we get rid of requiring the safe attributes railtie by default.

I can work on this if you approve of this solution. Thanks!

Could you support STI reserved words?

ActiveRecord::SubclassNotFound

The single-table inheritance mechanism failed to locate the subclass: 'admin'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite User.inheritance_column to use another column for that information.

Not working.

class User < ActiveRecord::Base
  include SafeAttributes::Base
  bad_attribute_names :type

  scope :admins, -> { where(users: { type: 'admin' }) }
end

Working.

class User < ActiveRecord::Base
  self.inheritance_column = :_type_disabled

  scope :admins, -> { where(users: { type: 'admin' }) }
end
Env Version
Ruby 2.3.0
Rails 4.2.6

Rails 4 support.

Hi,

I'm migrating a legacy app from rails 2 - rails 4. I have a column format in my table which is clashing with instance_method name(and gettin private method format' called for #<Template:0x00000009d9b8c8> error). So I used this gem. It was working fine with rails 3 but after moving to rails4(and ruby 2.2.x) its not working. I started getting same issue. Can some one help me in solving the issue please

'stack level too deep' rails4

When using safe_attributes gem I get a 'stack level too deep' error 500 internal server error

The issue seems to be related to rendering with errors.

I have seen the incompatibility issue with Rails4 but I felt it would be good to leave it here anyway.

Error saving new model with "attribute" attribute

I think I found 1 case where your gem fails. I can read and update models with an attribute column named "attribute", but I cannot save a new one when the attribute name is "attribute". Other attribute names work fine for all methods.

Try this with Ruby 1.9.2 and Rails 3.1.3

rails g model TestModel

CreateTestModels.rb

class CreateTestModels < ActiveRecord::Migration
  def change
    create_table :test_models do |t|
      t.string :attribute
      t.timestamps
    end
  end
end

TestModel.rb

class TestModel < ActiveRecord::Base
  bad_attribute_names :attribute

  def blah= value
    self[:attribute] = value
  end

  def blah
    self[:attribute]
  end

end

rails console
Loading development environment (Rails 3.1.3)
ruby-1.9.2-p290 :001 > t = TestModel.new
=> #<TestModel id: nil, attribute: nil, created_at: nil, updated_at: nil>
ruby-1.9.2-p290 :002 > t.blah = 'blah'
=> "blah"
ruby-1.9.2-p290 :003 > t.save
(512.0ms) BEGIN
SQL (295.2ms) INSERT INTO test_models (attribute, created_at, updated_at) VALUES ('blah', '2011-12-09 06:00:21', '2011-12-09 06:00:21')
(305.7ms) ROLLBACK
ArgumentError: wrong number of arguments (0 for 1)
from /Users/kmatthews812/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.3/lib/active_record/attribute_methods/read.rb:141:in attribute' from /Users/kmatthews812/.rvm/gems/ruby-1.9.2-p290/gems/activemodel-3.1.3/lib/active_model/dirty.rb:143:inattribute_change'
from /Users/kmatthews812/.rvm/gems/ruby-1.9.2-p290/gems/activemodel-3.1.3/lib/active_model/dirty.rb:117:in `block in changes'

The strange part is that the data is actually saved to the database. The error is thrown after the data is saved and the rollback never occurs. Any ideas on how to fix this? I have no ability to change the database column name, as this is a legacy database.

Thanks!

Incompatible with Rails 4

Placeholder, after testing against Rails 4 beta1 it is clear the current code does not work with Rails 4. If someone wants to take a stab at fixing it I won't mind the pull request.

ID is excluded?

I'm looking for a solution to be able to write a column named 'ID' (which isn't the primary key) in an external database.

I noticed in the README it says

Instance methods in ActiveRecord::Base, except for 'id', are combined into a list

Is there any reason why id is excluded? Is id= excluded too?

So far my best (only) solution is to monkey patch ActiveRecord::AttributeMethods::Write.write_attribute(attr_name, value) and then access it using square brackets:

external_object = ExternalObject.new(mapped_attributes_other_than_person_id)
external_object[:id] = person_id
external_object.save

Can't access 'attribute'

Fantastic plugin - my legacy db has the column 'attribute'

Is it possible to do this - right now I'm getting an error:

NoMethodError: Attempt to call private method `attribute'

S

Can I create a model instance with one of parameters named *attributes*?

I have a legacy DB. One of the columns is named attributes. It does cause lots of pain even with bad_attribute_names :attributes. I was trying to call MyModule::MyModel.new(params_with_attributes), but I get an ArgumentError exception in #assign_attributes at activerecord (4.2.10) lib/active_record/attribute_assignment.rb saying When assigning attributes, you must pass a hash as an argument.. Is it the dead end? I'm about to rename the column.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.