Rails 3 Setting Up Action Mailer - ruby-on-rails-3

Everything was going so well...
gem 'mail' is installed
enter > $ rails g scaffold user name:string email:string
enter > $ rake db:migrate (fine I can see it on http://localhost:3000/users/new) then...
enter > $ rails g mailer user_mailer
On this command I get this huge error - what is it and how do I resolve it?
Users/mailer_app/config/initializers/setup_mail.rb:14: uninitialized
constant DevelopmentMailInterceptor (NameError)
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/engine.rb:201
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/engine.rb:200:in `each'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/engine.rb:200
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:25:in `instance_exec'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:25:in `run'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:50:in `run_initializers'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:49:in `each'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:49:in `run_initializers'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:134:in `initialize!'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:77:in `send'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:77:in `method_missing'
from /Users/liam_carey/Documents/Aptana Studio 3 Workspace/mailer_test/config/environment.rb:5
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:103:in `require'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:103:in `require_environment!'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/commands.rb:16
from script/rails:6:in `require'
from script/rails:6
user:mailer_app $

Here is the contents of my config/initializers/setup_mail.rb
Am using Heroku and Sendgrid and have installed the plug-in.
Did I need to install the 'mail' gem first, the documentation doesn't mention it??
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => "25",
:authentication => :plain
:user_name => "apxxxxx#heroku.com",
:password => "9XXXXXXXXX",
:domain => "www.myapp.com",
}
I know what the issue is now - there is no comma after the user-name and password entries!

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

ckeditor in Rails 3.0.9

i have my project with Rails 3.0.9 and i added the CKeditor 3.6.3, in development works fine, and in Staging in Heroku works fine too, but in Production crash the app.
This are the configuration i have to production:
config/application.rb
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
config/environments/production.rb
#config.assets.precompile += Ckeditor.assets
I have commented the line because config.assets is not available until Rails 3.1, but i don't want to upgrade Rails in this moment.
app/models/ckeditor/attachment_file.rb
class Ckeditor::AttachmentFile < Ckeditor::Asset
has_attached_file :data,
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:url => ":s3_domain_url"
validates_attachment_size :data, :less_than => 100.megabytes
validates_attachment_presence :data
def url_thumb
#url_thumb ||= Ckeditor::Utils.filethumb(filename)
end
end
app/models/ckeditor/picture.rb
class Ckeditor::Picture < Ckeditor::Asset
has_attached_file :data, :styles => { :content => '800>', :thumb => '118x100#' },
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":picture/:id/:style.:extension",
:url => ":s3_domain_url"
validates_attachment_size :data, :less_than => 2.megabytes
validates_attachment_presence :data
def url_content
url(:content)
end
end
And i received the next error:
/home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library': uninitialized constant Ckeditor::Asset (NameError)
from /home/jorge/trabajos/blanet/app/models/ckeditor/attachment_file.rb:1:in `<top (required)>'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/engine.rb:138:in `block (2 levels) in eager_load!'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/engine.rb:137:in `each'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/engine.rb:137:in `block in eager_load!'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/engine.rb:135:in `each'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/engine.rb:135:in `eager_load!'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/application.rb:108:in `eager_load!'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/application/finisher.rb:41:in `block in <module:Finisher>'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `instance_exec'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `run'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/initializable.rb:50:in `block in run_initializers'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `each'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `run_initializers'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/application.rb:134:in `initialize!'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/application.rb:77:in `method_missing'
from /home/jorge/trabajos/blanet/config/environment.rb:5:in `<top (required)>'
from /home/jorge/trabajos/blanet/config.ru:3:in `block in <main>'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/builder.rb:46:in `instance_eval'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/builder.rb:46:in `initialize'
from /home/jorge/trabajos/blanet/config.ru:1:in `new'
from /home/jorge/trabajos/blanet/config.ru:1:in `<main>'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/builder.rb:35:in `eval'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/builder.rb:35:in `parse_file'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/server.rb:162:in `app'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/server.rb:253:in `wrapped_app'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/server.rb:204:in `start'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/commands/server.rb:65:in `start'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/commands.rb:30:in `block in <top (required)>'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/commands.rb:27:in `tap'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Any one can help me?
Thanks for advance.
It looks like it can't load the parent class for your attachments. Is Ckeditor::Asset defined somewhere? Is it being loaded? Maybe you need a require ckeditor/asset somewhere?

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|

Gem Koala undefined methods 'get_object'

I wanted to use Koala Gem to connect to Facebook api but I faced some problems.
Before I used Koala, I used omniauth-facebook to implement the SSO of my app.
And then I added gem koala in Gemfile and run bundle install.
In my `user.rb'
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
def facebook
#facebook = Koala::Facebook::API.new(oauth_token)
end
And then I go to consoele.
u = User.first
User Load (0.5ms) SELECT "users".* FROM "users" LIMIT 1
=> #<User id: 1, provider: "facebook", uid: "100003544640331", name: "Gary Lai", oauth_token: "AAAB9iQ1zm2oBAA1w3DFBZBC2V73uheQCs43dHpOu1LYsYixqvu...", oauth_expires_at: "2012-10-02 09:55:39", created_at: "2012-07-27 16:41:18", updated_at: "2012-08-03 09:55:42">
It works.
However, when I follow the kaola tutorial, I got this error message.
u.facebook.get_object("me")
NoMethodError: undefined method `get_object' for #<Koala::Facebook::API:0x007fb07ab1e108>from (irb):8
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Why I got this error message ?
Finally, I solved this problem. Cause my koala version were 1.0. Therefore I have to use gem 'koala', :git => 'https://github.com/arsduo/koala.git'

Getting an error with custom validation in a Rails 3 ActiveModel

I'm trying to use the Date Validator Gem but I am running into an error and I'm not sure if it's because the model isn't Active Record or not (I've seen people suggest that validation is a bit funky in ActiveModel when not in ActiveRecord).
I am using Ruby 1.9.2 & Rails 3.0.7. I've attached both the class and the error below.
Thanks in advance for any help!
Class
require 'ice_cube'
require 'active_support'
require 'active_support/time_with_zone'
require 'ostruct'
require 'tzinfo'
require 'active_model'
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
class Schedule
attr_accessor :yaml, :repeat, :interval, :interval_unit, :start_time, :start_date, :end_date, :end_time, :ends, :on, :after, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday
validates_presence_of :repeat, :start_date, :start_time, :end_date, :end_time, :ends
validates_presence_of :interval, :interval_unit, :if => :ends_never?
validates_presence_of :on, :if => :ends_on_date?
validates_numericality_of :after, :greater_than => 0, :if => :ends_after_recurrences?
validates :start_date, :date => { :after => Time.now }
validates :end_date, :date => { :after => :start_date }
validates :on, :date => { :after => :end_date }
def initialize(attributes = {})
end
def persisted?
false
end
private
def parse_schedule
if :repeat == 0
get_repeatable
end
end
def parse_yaml
end
def ends_on_date?
return :ends == "on"
end
def ends_never?
return :ends == "never"
end
def ends_after_recurrences?
return :ends == "after"
end
end
Error from Rails Console
ruby-1.9.2-p180 :001 > s = Schedule.new
NoMethodError: undefined method `new' for DateValidator:Module
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/with.rb:70:in `block in validates_with'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/with.rb:69:in `each'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/with.rb:69:in `validates_with'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/validates.rb:90:in `block in validates'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/validates.rb:83:in `each'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/validates.rb:83:in `validates'
from /Users/chance/Sites/EatingNow/app/models/schedule.rb:16:in `<class:Schedule>'
from /Users/chance/Sites/EatingNow/app/models/schedule.rb:10:in `<top (required)>'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:454:in `load'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:454:in `block in load_file'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:596:in `new_constants_in'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:453:in `load_file'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:340:in `require_or_load'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:491:in `load_missing_constant'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:183:in `block in const_missing'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:181:in `each'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:181:in `const_missing'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/rspec-expectations-2.5.0/lib/rspec/expectations/backward_compatibility.rb:6:in `const_missing'
from (irb):1
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/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>'
You have included/extended the top-level namespace. Make sure the includes/extends are IN the class.
class Schedule
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming