The issue here is that the attr_accessible ...
statement is never reached. The reason is because of that erroneous include PublicID
, and here's why:
Consider the following console statement:
Template.create(:title => "omg")
It will output the following stack trace:
1.9.3-p362 :001 > Template.create(:title => "omg")
TypeError: wrong argument type String (expected Module)
from /Users/r/Sites/MicroEval/ror/app/models/template.rb:2:in `include'
from /Users/r/Sites/MicroEval/ror/app/models/template.rb:2:in `<class:Template>'
from /Users/r/Sites/MicroEval/ror/app/models/template.rb:1:in `<top (required)>'
from /Users/r/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2ndEd/gems/activesupport-3.2.11/lib/active_support/dependencies. rb:469:in `load'
from /Users/r/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2ndEd/gems/activesupport-3.2.11/lib/active_support/dependencies. rb:469:in `block in load_file'
from /Users/r/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2ndEd/gems/activesupport-3.2.11/lib/active_support/dependencies. rb:639:in `new_constants_in'
from /Users/r/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2ndEd/gems/activesupport-3.2.11/lib/active_support/dependencies. rb:468:in `load_file'
from /Users/r/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2ndEd/gems/activesupport-3.2.11/lib/active_support/dependencies. rb:353:in `require_or_load'
from /Users/r/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2ndEd/gems/activesupport-3.2.11/lib/active_support/dependencies. rb:502:in `load_missing_constant'
from /Users/r/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2ndEd/gems/activesupport-3.2.11/lib/active_support/dependencies. rb:192:in `block in const_missing'
from /Users/r/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2ndEd/gems/activesupport-3.2.11/lib/active_support/dependencies. rb:190:in `each'
from /Users/r/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2ndEd/gems/activesupport-3.2.11/lib/active_support/dependencies. rb:190:in `const_missing'
from (irb):1
from /Users/r/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2ndEd/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from /Users/r/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2ndEd/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from /Users/r/.rvm/gems/ruby-1.9.3-p362@rails3tutorial2ndEd/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top ( required)>'
from script/rails:6:in `require'
As you can see there is an error with the include
, and that is because the proper module has not been first required.
Adding a simple require "publicid"
to the top of the Template
model will ensure that the module can indeed be included.
As another note, the module lives in /lib
where /
refers to the root of your app.
Thanks to the @radar on #rubyonrails IRC channel for the answer.