Entries tagged with “ruby on rails”.
Did you find what you wanted?
Mon 30 Mar 2009
Problem
Upgrading from a previous version of Rails to the latest 2.3.2, you get an error:
NameError: uninitialized constant ApplicationController
both in the web browser and in console.
Solution
Since the introduction of Rails 2.3 the application.rb file has been renamed to application_controller.rb.
So in order to solve the problem just rename your file application.rb to application_controller.rb.
Thanks to the post here
Thu 19 Feb 2009
Posted by kosmas under ruby on rails
No Comments
Problem
You want to use ActiveScaffold in Rails 2.2, in a model that you have created using the standard Rails scaffolding script.
Solution
- Install the ActiveScaffold plugin:
script/plugin install git://github.com/activescaffold/active_scaffold.git -r rails-2.2
- In your layout (model or application for all models) add the following:
<%= javascript_include_tag :defaults %>
<%= active_scaffold_includes %>
- In your controller file delete all the standard scaffolding code and add one line, so that your new controller should look like:
class SomethingsController < ApplicationController
active_scaffold :something
end
- To configure a RESTful scaffold add the following to your route.rb file:
map.resources :somethings, :active_scaffold => true
- Delete the views that were created from the standard rails scaffolding in the views/somethings folder (edit, show, index ...)
- Restart your server
You should now have an active scaffold for your model.
Mon 26 Jan 2009
Problem
You are using the script/dbconsole utility in Rails (with sqlite), and you want to exit the application but the usual keystrokes/commands like quit, exit, Ctrl + C don’t work.
Solution
You have to use the following keyword, paying particular notice in the leading dot (.exit):
.exit
Wed 21 Jan 2009
Problem
You want to work with sqlite3 in Mandriva (2009), but the standard installation doesn’t work, and you cannot use urpmi sqlite3.
Solution
You need to install the sqlite3 command line tools, like:
urpmi sqlite3-tools
Fri 31 Oct 2008
Posted by kosmas under ruby on rails
No Comments
Problem
When trying to use the acts_as_ferret plugin in a search page by using the find_by_contents method then the following error appears:
undefined method `find_by_contents'
Solution
It seems that the API of the plugin has changed, and the
find_by_contents
method should be replaced with the:
find_with_ferret
method
Tue 21 Oct 2008
Problem
After a recent upgrade to a newer rails version the gem package manager seems to be broken. Everytime you try to use gem install gem_name, you get the following error:
ERROR: While executing gem ... (Gem::GemNotFoundException)
Deleting the cached files as suggested in other posts results in the error:
ERROR: While executing gem ... (ArgumentError)
Solution
As suggested here, you need to do:
gem install rubygems-update
update_rubygems
which should be updating the gem version to the latest one, ie 1.3.0
Thu 2 Oct 2008
Problem
When trying to use facebooker according to the Developing facebook platform applications with rails book, in the network_test step you are getting the following error:
FBML Error (line 5): illegal tag "body" under "fb:canvas"
Solution
It should be caused because you are using the facebooker gem instead of the plugin.
Install the plugin:
ruby script/plugin install git://github.com/mmangino/facebooker.git
Tue 30 Sep 2008
Posted by kosmas under ruby on rails
No Comments
Problem
Following from a previous post about email scheduling with runner and cron, it turns out that the runner default behaviour is to run in the development environment.
Solution
Although by reading the help for the script/runner, there is a suggestion to run it with the -e production
added to the end, it doesn’t seem to be working.
The solution to make it running in the production environment was to delete the first line (shebang) from step 3 on this post
#!/usr/bin/env /path_to_your_app/script/runner
and then use the following in the cron setup:
RAILS_ENV=production /path/to/your_ror_project/script/runner /path/to/your_ror_project/lib/email_scheduler.rb
Have a look on paragraph Alternative Usage here
Wed 16 Jul 2008
Posted by kosmas under ruby on rails
No Comments
Problem
You are developing on the latest version of Rails (2.1), but your production server for deployment uses version 2.0.2 (as dreamhost is using at the moment).
Solution
- First change the environment.rb file to use the rails version in your deployment server
RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
- You should probably be geting the error: undefined method = time zone by now, so make sure you comment out from further down your environment.rb file the line:
config.time_zone = 'UTC'
- Some further errors would be caused by the file config/initializers/new_rails_defaults.rb, so make sure you comment out the following lines:
ActiveRecord::Base.include_root_in_json = true
ActiveRecord::Base.store_full_sti_class = true
ActiveSupport.use_standard_json_time_format = true
ActiveSupport.use_standard_json_time_format = true
You should be able to deploy and use your application now.
Wed 11 Jun 2008
Problem
You want to send emails from a Ruby on Rails application, when there is a specific condition on a database table. If the database table gets modified by another application outside Rails you cannot use an observer model.
Solution
We already assume that:
- You are using a database
- You have a model named voicemail (id, number_id, audio, created_at, updated_at)
- You have a model named number (id, voicemail_email_set, voicemail_email, ….)
- A mail server to use (smtp in our case)
- Another application (voice application) populates the voicemail table but with empty updated_at values
So the steps we have to follow are:
- Change the settings in your config/environment.rb file to use the settings for your mail server, and make sure you restart your application after the changes:
ActionMailer::Base.smtp_settings = {
:address => "yourmailserver.com",
:port => 25,
:domain => "your.domain.com",
:authentication => :login,
:user_name => "your_smtp_username",
:password => "your_smtp_password",
:raise_delivery_errors => true}
- Create your mailer model (ie voicemail_mailer.rb), in app/models:
class VoicemailMailer < ActionMailer::Base
# We need the open-uri to be able to open url *** if the file to attach is in an http location ***
require 'open-uri'
def sent(email_to,email_from,email_subject,email_body,voicemail_to_send)
# Check to see if we have a file for the email body message
@subject = email_subject
@body = email_body
@recipients = email_to
@from = email_from
@sent_on = Time.now
# Split the file in directory and filename
file_path = File.split(voicemail_to_send)
file_dir = file_path[0]
file_name = file_path[1]
# Get the file
tmp_file = open(voicemail_to_send).read
part( :content_type => "application/wav",
:disposition => "attachment; filename=#{file_name}",
:transfer_encoding => "base64") do |attachment|
attachment.body = tmp_file
end
end
end
- Create your email scheduler in file lib/email_scheduler.rb:
#!/usr/bin/env /path_to_your_app/script/runner
# get all the voicemails that have not been sent yet
voicemails_to_email = VoiceMail.find(:all, :conditions => 'updated_at is null')
# For all the voicemails we have, send them and update the field date_sent
for vm2email in voicemails_to_email do
# Get the number for the voicemail
number = Number.find(vm2email.number_id)
# check to see if the send to email is set for the number
if number.voicemail_email_set
# Get number details (email_to,email_from etc)
email_to = number.voicemail_email
voicemail_to_send = vm2email.audio
# Set other details
email_from = 'Service@yourdomain.com'
email_subject = 'Please find attached your voicemail message'
email_body = "Received on: #{Time.now} \n for number: #{number.phone_no}"
# Now send the email
VoicemailMailer.deliver_sent(email_to,email_from,email_subject,email_body,voicemail_to_send)
# And update the record's date_sent field
vm2email.updated_at = Time.now
vm2email.save
end
end
- Create a task in your crontab that runs the scheduler (every five minutes):
0,5,10,15,20,25,30,35,40,45,50,55 * * * * path_to_your_ror_app/lib/email_scheduler.rb