Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using rails 3.2, the generator adds 'attr_accessible' to the model.... #2522

Merged
merged 1 commit into from
Jul 26, 2013

Conversation

jcoyne
Copy link
Contributor

@jcoyne jcoyne commented Jul 23, 2013

... Fixes #2515

end

def needs_attr_accessible?
Rails::VERSION::MAJOR == 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should simply check if ActionController::StrongParameters is defined or not?

@josevalim
Copy link
Contributor

Thanks @jcoyne! I have added one small comment and your pull request fails the test suite, could you please take a look? Thanks!

@jcoyne
Copy link
Contributor Author

jcoyne commented Jul 23, 2013

@josevalim I've fixed the build and now I'm checking for ActionController::StrongParameters

end

def needs_attr_accessible?
!ActionController.const_defined? :StrongParameters
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use defined?(ActionController::StrongParameters) here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make a difference?

@latortuga
Copy link
Contributor

As I stated in the original issue, you should include the attr_accessible call if they're on Rails 3.2 and don't have strong_parameters included OR if they're on Rails 4 and have the protected_attributes gem included. Checking for StrongParameters will yield a false positive in Rails 4 if using the protected_attributes gem.

Does it make a difference?

We should do the most correct thing that we possibly can and in this case, we have enough information to make a good decision about including this line.

@jcoyne
Copy link
Contributor Author

jcoyne commented Jul 23, 2013

Okay, I didn't exactly understand all the possible permutations. I though @nashby was just arguing the merits of defined?(ActionController::StrongParameters) vs ActionController.const_defined? :StrongParameters

@jcoyne
Copy link
Contributor Author

jcoyne commented Jul 23, 2013

@latortuga I'm still not sure I have all the permutations straight. Something like this?

def needs_attr_accessible?
  case Rails::VERSION::MAJOR
  when 3
    !defined?(ActionController::StrongParameters)
  when 4
    defined?(ActiveModel::MassAssignmentSecurity)
  end
end

@latortuga
Copy link
Contributor

@jcoyne I like that implementation 👍. I would like some others' thoughts on perhaps checking the Rails config option config.active_record.whitelist_attributes because I think it may have been removed/deprecated in Rails 4.

@jcoyne
Copy link
Contributor Author

jcoyne commented Jul 25, 2013

There was an error in the build ("Could not find devise-3.0.0.rc in any of the sources") can someone with permissions restart it?

josevalim pushed a commit that referenced this pull request Jul 26, 2013
When using rails 3.2, the generator adds 'attr_accessible' to the model....
@josevalim josevalim merged commit 14a0cfe into heartcombo:master Jul 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

When using devise 3.0.0 with Rails 3.2, attr_accessible is not generated on model
4 participants