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

Make it work for Rails 3 #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The method is to scan the controllers for likely mass assignment, and then find

Install this plugin as follows:

$ script/plugin install git://github.com/mhartl/find_mass_assignment.git
$ rails plugin install git://github.com/mhartl/find_mass_assignment.git

For more information, see my [brief review of mass assignment](http://blog.mhartl.com/2008/09/21/mass-assignment-in-rails-applications/) and my discussion of [how to fix mass assignment vulnerabilities in Rails](http://blog.mhartl.com/2008/09/21/finding-and-fixing-mass-assignment-problems-in-rails-applications/).

Expand Down
7 changes: 5 additions & 2 deletions lib/find_mass_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def mass_assignment?
# Note that 'attr_accessible' must be preceded by nothing other than
# whitespace; this catches cases where attr_accessible is commented out.
def attr_accessible?
model = "#{RAILS_ROOT}/app/models/#{self.underscore}.rb"
model = "#{Rails.root}/app/models/#{self.underscore}.rb"
if File.exist?(model)
return @@cache[model] unless @@cache[model].nil?
@@cache[model] = File.open(model).read =~ /^\s*attr_accessible/
Expand Down Expand Up @@ -86,7 +86,7 @@ def self.print_mass_assignment_problems(controller)
# and then run
# $ chmod +x git/hooks/pre-commit
def self.find
controllers = Dir.glob("#{RAILS_ROOT}/app/controllers/**/*_controller.rb")
controllers = Dir.glob("#{Rails.root}/app/controllers/**/*_controller.rb")
exit_status = 0
controllers.each do |controller|
if controller.mass_assignment_problem?
Expand All @@ -95,6 +95,9 @@ def self.find
exit_status = 1
end
end
rescue => e
puts e.message
puts e.backtrace.join("\n")
ensure
Process.exit exit_status
end
Expand Down