test rails controllers that are not in spec/controllers with rspec 2 - ruby-on-rails-3

rspec expects your controller specs to be in /spec/controllers. I have some modules that are included in my controllers. The only way to test them, near as I can tell, is to create a dummy controller, include the module in it, and test from there. The problem is that the module specs are in /spec/lib/module, and so ControllerExampleGroup is not included, which means I can't call the helper methods get "action" etc.
I can manually import these, which gets me most of the way there, but I then get this error:
Failure/Error: Unable to find matching
line from backtrace undefined method
`path_set' for nil:NilClass
activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in
`method_missing'
rspec-rails-2.2.1/lib/rspec/rails/view_rendering.rb:68
rspec-core-2.2.1/lib/rspec/core/example_group.rb:291:in
`instance_eval'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:291:in
`instance_eval_with_rescue'
rspec-core-2.2.1/lib/rspec/core/hooks.rb:39:in
`run_in'
rspec-core-2.2.1/lib/rspec/core/hooks.rb:70:in
`run_all'
rspec-core-2.2.1/lib/rspec/core/hooks.rb:70:in
`each'
rspec-core-2.2.1/lib/rspec/core/hooks.rb:70:in
`run_all'
rspec-core-2.2.1/lib/rspec/core/hooks.rb:106:in
`run_hook'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:194:in
`eval_after_eachs'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:194:in
`each'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:194:in
`eval_after_eachs'
rspec-core-2.2.1/lib/rspec/core/example.rb:130:in `run_after_each'
rspec-core-2.2.1/lib/rspec/core/example.rb:44:in `run'
rspec-core-2.2.1/lib/rspec/core/example.rb:88:in `with_around_hooks'
rspec-core-2.2.1/lib/rspec/core/example.rb:37:in `run'
rspec-core-2.2.1/lib/rspec/core/example.rb:81:in `with_pending_capture'
rspec-core-2.2.1/lib/rspec/core/example.rb:80:in `catch'
rspec-core-2.2.1/lib/rspec/core/example.rb:80:in `with_pending_capture'
rspec-core-2.2.1/lib/rspec/core/example.rb:36:in `run'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:261:in
`run_examples'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:257:in
`map'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:257:in
`run_examples'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:231:in
`run'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:232:in
`run'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:232:in
`map'
rspec-core-2.2.1/lib/rspec/core/example_group.rb:232:in
`run'
rspec-core-2.2.1/lib/rspec/core/command_line.rb:27:in
`run'
rspec-core-2.2.1/lib/rspec/core/command_line.rb:27:in
`map'
rspec-core-2.2.1/lib/rspec/core/command_line.rb:27:in
`run'
rspec-core-2.2.1/lib/rspec/core/reporter.rb:12:in `report'
rspec-core-2.2.1/lib/rspec/core/command_line.rb:24:in
`run'
rspec-core-2.2.1/lib/rspec/core/runner.rb:55:in
`run_in_process'
rspec-core-2.2.1/lib/rspec/core/runner.rb:46:in
`run'
rspec-core-2.2.1/lib/rspec/core/runner.rb:10:in
`autorun'
/Users/jeffdeville/.rvm/gems/ree-1.8.7-2010.02/bin/rspec:19
Suggestions?

If you have a spec that's not in one of the standard locations, you can always tell rspec by passing a :type attribute to the describe method:
describe MyController, :type => :controller do
...
end
For specing modules that are meant to be included by a controller, rspec 2 has a very handy way to create anonymous controllers.
describe MyModule do
context "when included by a controller", :type => :controller do
controller do # anonymous subclass of ActionController::Base
include MyModule
def index
head :ok
end
end
it "works" do
get "index"
response.should be_success
end
end
end
More info here in the rspec docs (generated from Cucumber features): http://relishapp.com/rspec/rspec-rails/dir/controller-specs/anonymous-controller

Related

Devise Backbone Heroku and require.js on Rails configuration

Ok, so I know I am playing with the big boys and girls here messing with front and backend MVC (even though bbone isn't exactly MVC) for an application, but this is the first real robust application I have ever worked on, and unfortunately being in the academics realm, support isn't there, esp for more cutting edge, so I am thankful in advance.
I have some errors when trying to deploy to Heroku with a Rails (3.2.2) app, and the asset pipeline has been causing problems all the time. Since I am using BBone for the front end, and the [single]page[app] needs to know the paths to images and sounds on load, I had to use this gist to attach the image paths to the App.assets to pass to the application.js file for require.js to start the application being built on the front end.
The problem appears to be that Devise wants: config.assets.initialize_on_precompile = false while require wants: config.assets.initialize_on_precompile = true and Heroku wants in the production.rb file to be: config.assets.compile = true.
The error I am getting is in the gist file assets.js.erb where the call is made to the DB to get all the songs in the Song model, second to last line
App = {};
App.assets = {
// Returns an object containing all of asset pipeline's image paths.
//
// Sample:
//
// {
// avatars/missing_avatar.png: "/assets/avatars/missing_avatar.png"
// chosen-sprite.png: "/assets/chosen-sprite.png"
// circle_green.png: "/assets/circle_green.png"
// circle_orange.png: "/assets/circle_orange.png"
// circle_red.png: "/assets/circle_red.png"
// circle_yellow.png: "/assets/circle_yellow.png"
// document.png: "/assets/document.png"
// }
//
// This hash is because Rails' Asset Pipeline bundles the routes to files
// per user session, then hands that to the user's session browser, for security.
// So we create in Ruby (erb = embedded ruby) a hash of the images to be accessed
// in the JS.
images: {
<% AssetsUtil.images.each do |img| %>
"<%= img %>" : "<%= asset_path(img) %>",
<% end %>
},
// Return a formatted URL for an asset.
//
// Sample:
//
// "/assets/document/png."
//
path: function(name) {
// If the file is in our images object, pull the path from there.
if (this.images && this.images[name]) {
return this.images[name];
}
// Otherwise, create a generic asset path.
return '/assets/' + name;
}
};
// Currently this is ALL the songs in the DB, not just the current_user 's songs
App.songs = {
songs: <%= Song.all.to_json.html_safe %>
};
The full trace error trying to rake assets:precompile as suggested todo before deploying to Heroku is:
** Invoke assets:precompile (first_time)
** Invoke requirejs:precompile:external (first_time)
** Invoke requirejs:test_node (first_time)
** Execute requirejs:test_node
** Execute requirejs:precompile:external
/Users/me/.rvm/rubies/ruby-1.9.3-p362/bin/ruby /Users/me/.rvm/gems/ruby-1.9.3-p362/bin/rake requirejs:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke requirejs:precompile:all (first_time)
** Invoke requirejs:precompile:prepare_source (first_time)
** Invoke requirejs:setup (first_time)
** Invoke assets:environment (first_time)
** Invoke requirejs:precompile:disable_js_compressor (first_time)
** Execute requirejs:precompile:disable_js_compressor
** Execute assets:environment
** Execute requirejs:setup
** Invoke requirejs:clean (first_time)
** Invoke requirejs:setup
** Execute requirejs:clean
** Execute requirejs:precompile:prepare_source
rake aborted!
uninitialized constant Song
(in /Users/me/dev/SoundOfFractions/app/assets/javascripts/assets.js.erb)
/Users/me/dev/SoundOfFractions/app/assets/javascripts/assets.js.erb:48:in `block in singletonclass'
/Users/me/dev/SoundOfFractions/app/assets/javascripts/assets.js.erb:65530:in `instance_eval'
/Users/me/dev/SoundOfFractions/app/assets/javascripts/assets.js.erb:65530:in `singletonclass'
/Users/me/dev/SoundOfFractions/app/assets/javascripts/assets.js.erb:65528:in `__tilt_70168709646800'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/tilt-1.3.4/lib/tilt/template.rb:144:in `call'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/tilt-1.3.4/lib/tilt/template.rb:144:in `evaluate'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/tilt-1.3.4/lib/tilt/template.rb:77:in `render'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/context.rb:177:in `block in evaluate'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/context.rb:174:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/context.rb:174:in `evaluate'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/processed_asset.rb:12:in `initialize'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:241:in `new'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:241:in `block in build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:262:in `circular_call_protection'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:240:in `build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:89:in `block in build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/caching.rb:19:in `cache_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:88:in `build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:163:in `find_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:56:in `find_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/bundled_asset.rb:16:in `initialize'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:244:in `new'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:244:in `build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:89:in `block in build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/caching.rb:19:in `cache_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:88:in `build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:163:in `find_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:56:in `find_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/requirejs-rails-0.9.1/lib/tasks/requirejs-rails_tasks.rake:94:in `block (4 levels) in <top (required)>'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:212:in `block in each_logical_path'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:200:in `block (2 levels) in each_file'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:190:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:190:in `each_entry'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:198:in `block in each_file'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:197:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:197:in `each_file'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:210:in `each_logical_path'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/requirejs-rails-0.9.1/lib/tasks/requirejs-rails_tasks.rake:92:in `block (3 levels) in <top (required)>'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:187:in `block in invoke_prerequisites'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:185:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:185:in `invoke_prerequisites'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:165:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/rake:19:in `load'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/rake:19:in `<main>'
Tasks: TOP => requirejs:precompile:all => requirejs:precompile:prepare_source
rake aborted!
Command failed with status (1): [/Users/me/.rvm/rubies/ruby-1.9.3-p362...]
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `call'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `sh'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:40:in `sh'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/file_utils.rb:80:in `ruby'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:40:in `ruby'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.2/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/requirejs-rails-0.9.1/lib/tasks/requirejs-rails_tasks.rake:85:in `block (3 levels) in <top (required)>'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:187:in `block in invoke_prerequisites'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:185:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:185:in `invoke_prerequisites'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:165:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/rake:19:in `load'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/rake:19:in `<main>'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `eval'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => assets:precompile => requirejs:precompile:external
gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.2'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'railroady'
gem 'sqlite3'
# For linux support
gem 'therubyracer'
end
group :production do
gem 'pg'
gem 'thin'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'uglifier', '>= 1.0.3'
end
# gem "better_errors", ">= 0.2.0", :group => :development
# gem "binding_of_caller", ">= 0.6.8", :group => :development
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'jquery-rails'
gem 'rails-backbone'
gem "bootstrap-sass", "~> 2.3.0.0"
gem 'requirejs-rails'
gem 'ejs'
gem 'devise'
gem "better_errors", ">= 0.2.0", :group => :development
gem "binding_of_caller", ">= 0.6.8", :group => :development
gem 'color_routes'
gem 'gon'
So where should I start with my configuration to finish deployment?
Potential info:
If you watch how to make custom rake tasks from Railscasts here, the same error occurs when running the custom rake task, and Ryan explains that the task can't access the DB because the custom task needs an => :environment dependency (~4:15 in the movie) to access the User class. Since the precompile can't access the songs model, how could I provide the same or similar dependency to the application.js file?
OTHER info:
To my understanding the way the asset pipeline works is for each session, it bundles the paths (so when you type something like <%= link_to 'Sign in', new_user_path %>, rails defines those paths in the asset pipeline, and serves it to the user. Since Backbone is client side rendering, it needs to know the paths to the images and sounds after the page is handed from the rails server, and the only way to do this that I found was the gist listed above, where it bundles the "assets" to the JS, a similar approach to gem 'gon' that provides global variables to the page. I of course am plying in new grounds, and open to restructuring, but it works in dev mode, so I am trying to figure out production as well.
The Rails Environment is not available to you during heroku asset precompile. As they are made once and not refreshed again tell the next deploy. That being said. You should move your dynamic DB related calls to your views and render the data either via API calls or "bootstraping" the data by writing your Javascript ton a script tag in the dom in json. I normally have window.NAME_OF_APPLICATION.collections.SONGS so they are available to me in a global scope.
Example.
:javascript
window.lineItems = {lineItems: #{ #order.line_items.order("position").to_json( :include => :department).html_safe}, order: #{#order.to_json} }
When Backbone comes online have it call for these items. And initialize a collection for them.
#burningpony's accepted answer above is not entirely correct.
The Rails env is available during heroku asset precompile if you use the labs plugin:
https://devcenter.heroku.com/articles/labs-user-env-compile

_localization suffix for models reserved in FactoryGirl

I have two models in my Rails application:
class Item < ActiveRecord::Base
end
class ItemLocalization < ActiveRecord::Base
end
Similarly, I have two factories:
factory :item do
sequence(:name) { |n| "item #{n}" }
description "this is a description"
association :locale, :factory => :locale_deCH
item_group
end
factory :item_localization do
sequence(:name) { |n| "item #{n}" }
description "this is a description"
association :locale, :factory => :locale_deCH
item
user
reviewer
end
When having a second factory with the _localization suffix, FactoryGirl returns a DuplicationError:
Rack::File headers parameter replaces cache_control after Rack 1.5.
/Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/factory_girl-4.1.0/lib/factory_girl/decorator.rb:10:in `method_missing': Factory already registered: item_localization (FactoryGirl::DuplicateDefinitionError)
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/factory_girl-4.1.0/lib/factory_girl/decorator/disallows_duplicates_registry.rb:6:in `register'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/factory_girl-4.1.0/lib/factory_girl.rb:65:in `block in register_factory'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/factory_girl-4.1.0/lib/factory_girl.rb:64:in `each'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/factory_girl-4.1.0/lib/factory_girl.rb:64:in `register_factory'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb:20:in `factory'
from /Users/user/Sites/ec/spec/factories.rb:62:in `block in <top (required)>'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb:49:in `instance_eval'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb:49:in `run'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb:7:in `define'
from /Users/user/Sites/ec/spec/factories.rb:1:in `<top (required)>'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `block in load'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/factory_girl-4.1.0/lib/factory_girl/find_definitions.rb:16:in `block in find_definitions'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/factory_girl-4.1.0/lib/factory_girl/find_definitions.rb:15:in `each'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/factory_girl-4.1.0/lib/factory_girl/find_definitions.rb:15:in `find_definitions'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/factory_girl_rails-4.1.0/lib/factory_girl_rails/railtie.rb:26:in `block in <class:Railtie>'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:34:in `call'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/railties-3.2.11/lib/rails/application/finisher.rb:59:in `block in <module:Finisher>'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/user/Sites/ec/config/environment.rb:5:in `<top (required)>'
from /Users/user/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/user/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/user/Sites/ec/spec/spec_helper.rb:3:in `<top (required)>'
from /Users/user/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/user/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/user/Sites/ec/spec/models/organization_spec.rb:1:in `<top (required)>'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `load'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `block in load_spec_files'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `each'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `load_spec_files'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/rspec-core-2.12.2/lib/rspec/core/command_line.rb:22:in `run'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:80:in `run'
from /Users/user/.rvm/gems/ruby-1.9.3-p327#rails329-ec/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:17:in `block in autorun'
Is the suffix "_localization" somehow reserved? Rails doesn't seem to have an issue with it.
I found the problem. It had nothing to do with the "_localization" suffix. Rather, when creating the model ItemLocalization, Rails created a factory with the same name in the folder test/factories and I used the same factory under rspec/factories.
Removing all files from the test/factories folder solved the issue.

rake aborted! undefined method `map' for :name:Symbol

I'm trying to pass arguments to a Rake task and access my model as mentioned in "How to pass command line arguments to a rake task" and "Do rails rake tasks provide access to ActiveRecord models?".
However adding => :environment to this code:
require 'rake'
namespace :genre do
desc "Add a genre"
task :add, :genre_id, :name => :environment do |t, args|
puts args.name
end
end
Gives me this error when I run the task:
rake genre:add['1','Abc']
rake aborted!
undefined method `map' for :name:Symbol
(See full trace by running task with --trace)
If I delete => :environment it works just fine.
UPDATE:
TRACE:
rake --trace genre:add['1','Abc']
rake aborted!
undefined method `map' for :name:Symbol
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:254:in `set_arg_names'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task_manager.rb:29:in `define_task'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:310:in `define_task'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/dsl_definition.rb:32:in `task'
/private/var/www/html/someapp.com/subdomains/someapp.heroku.com/someapp/lib/tasks/genre.rake:5:in `block in <top (required)>'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task_manager.rb:207:in `in_namespace'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/dsl_definition.rb:102:in `namespace'
/private/var/www/html/someapp.com/subdomains/someapp.heroku.com/someapp/lib/tasks/genre.rake:3:in `<top (required)>'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/engine.rb:425:in `load'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/engine.rb:425:in `block in load_tasks'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/engine.rb:425:in `each'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/engine.rb:425:in `load_tasks'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/application.rb:145:in `load_tasks'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
/private/var/www/html/someapp.com/subdomains/someapp.heroku.com/someapp/Rakefile:7:in `<top (required)>'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/user/.rvm/gems/ruby-1.9.2-p318/bin/rake:19:in `load'
/Users/user/.rvm/gems/ruby-1.9.2-p318/bin/rake:19:in `<main>'
Looks like your syntax is off. Try:
task :add, [:genre_id, :name] => :environment do |t, args|

Inject route from gem to rails 3 routes.rb using Railties (devise issue)

I would like to automatically inject a route from my gem to the host app using a railtie. So far I have something like this:
module Fabes
class FabesRailtie < ::Rails::Railtie
ActionController::Base.send :include, Fabes::Helper
ActionController::Base.helper Fabes::Helper
initializer 'fabes.routes', after: :after_initialize do |app|
app.routes.draw do
match '/fabes' => Fabes::Admin, as: :fabes_admin
end
end
end
end
This is working (is getting called from the host app) but when I try to access the /fabes route or just list the routes, it is failing with a devise error:
fuzzyalej#fuzzyalej:~/code/fabes-rails-example (master *)$ rake routes --trace
** Invoke routes (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
undefined method `failure_app=' for nil:NilClass
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/devise-2.1.2/lib/devise.rb:406:in `configure_warden!'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/devise-2.1.2/lib/devise/rails/routes.rb:20:in `finalize_with_devise!'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:261:in `draw'
/Users/fuzzyalej/code/fabes/lib/fabes/railtie.rb:7:in `block in <class:FabesRailtie>'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `instance_exec'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `run'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `each'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `run_initializers'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/application.rb:136:in `initialize!'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/fuzzyalej/code/fabes-rails-example/config/environment.rb:5:in `<top (required)>'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `block in require'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/application.rb:103:in `require_environment!'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/application.rb:292:in `block (2 levels) in initialize_tasks'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/bin/rake:23:in `load'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/bin/rake:23:in `<main>'
Tasks: TOP => routes => environment
I don't know if I can inject a route directly like this or instead I would have to use a generator..
Any thoughts on the issue?
Defining your routes in your gem's route.rb file and then mounting the engine is the way to go in this case.
The "official guide":
http://edgeguides.rubyonrails.org/engines.html
And of course, there's a RailsCast episode covering what you likely need:
http://railscasts.com/episodes/277-mountable-engines
Hope this helps.

Rails 3 - URL Helpers With Scoped Resource

I have a scoped resource in my routes file:
scope :module => "physical" do
resources :mymodels
end
Using '> rake routes' I get the standard routes, including:
mymodel GET /mymodels/:id(.:format) {:action=>"show", :controller=>"physical/mymodels"}
However when I use the console (and this is what's failing in my tests) to get the url for instances of Mymodel I get errors:
> m = Physical::Mymodel.new
> => {...model_attributes...}
> m.save
> => true
> app.url_for(m)
> NoMethodError: undefined method `physical_mymodel_url' for #<ActionDispatch::Integration::Session:0x00000105b15228>
from /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/testing/assertions/routing.rb:175:in `method_missing'
from /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/routing/polymorphic_routes.rb:114:in `polymorphic_url'
from /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/routing/url_for.rb:133:in `url_for'
from (irb):13
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
This might be a gotcha, but Mymodel is also a subclass using the standard Rails single table inheritance.
Any thoughts? Why is it looking for physical_mymodel_url instead of mymodel_url? Any ideas for workarounds so that I can still use the unprefixed routes?
You're only using the scope to tell it the module where the controller can be found in. If you want to use the physical prefix on your routes then you could do this:
scope :module => "physical", :as => "physical" do
resources :mymodel
end
Alternatively, you could just use the namespace method which will do the same thing:
namespace :physical do
resources :mymodel
end