Test Posting
May 22nd, 2009I am writing this posting as a test. A test of the system.
I am writing this posting as a test. A test of the system.
I’m back with some exciting news. I’m working with a group of people integrating the Joomla content management system (CMS) into a Ruby on Rails-served web site. Stay tuned for more tech info.
I had:
assert_invalid_column_on_record “user”, “password”
I tried replacing it with assert(record.errors.invalid?(column)) as the deprecation warning advised, but it did not work.
What did work was:
assert !user.valid?
assert user.errors.on(:password)
[Sending email from a Windows server using PHP]
I got the cryptic error message above while trying to send email using PHP from a Windows server. Turned out that the problem was that php.ini had set the sendmail_from entry to the silly value “me@localhost.com.” Since this is a shared hosting situation, we couldn’t change php.ini directly. However, we were able to use the ini_set function in the script that sent the mail:
ini_set(”sendmail_from”, “a-real-address@the-actual-domain.com”);
This fixed the problem.
I am doing some PHP work for LarryBeth now. I have switched from Windows to the Macintosh for development work, and for a text editor I use TextMate. I really like it, but its printing support is terrible. (It seems as if many people who create text editors forget about printing. I like to see code on paper — call me old-fashioned if you must.) The rough equivalent on Windows of TextMate is TextPad, and TextPad’s printing is pretty good. If you’re looking for an editor on the Mac with good printing support, I recommend jEdit.
I’ve learned (the hard way) a few more things about facilitating Rails automated testing when you are using Microsoft SQL Server.
Continuing the numbering from my prior post on this topic:
(3) In order for the built-in rake testing tasks (such as rake test:functionals) to work, you will need to uncomment the following line in your config/environment.rb file:
config.active_record.schema_format = :sql
If you don’t do this, Rails will try to autogenerate the schema.rb file as for MySQL and it will be a mess.
(4) Also in order for the built-in rake testing tasks to work, you need to have the rather obscure Microsoft utility called “scptxfr” on your DOS path. (scptxfr creates a SQL script from your database.) In my installation it was located in C:\Program Files\Microsoft SQL Server\80\Tools\Upgrade. To change the path, right-click on the My Computer icon, and choose Properties -> Advanced tab -> Environment Variables.
Earlier: Part 1
I was having real problems with my iPhone in the past couple of days. Using Cover Flow would cause a software crash (it would just abruptly switch back to the home page). Also, just playing the iPod would make it crash. It seems to be OK now. This is what I did to fix it:
(1) When using your own images (images you have not gotten from iTunes) for album art in iTunes, you must add the image to all tracks on the album. (My mistake was only adding the art to the first track). Select all the tracks, right click and choose Get Info.
(2) Powering off and on the iPhone ultimately fixed the problem. Ah, powering off and on, the technician’s friend. This Apple support doc is somewhat buried on their site. I did this:
Turn iPhone off and turn it on again. Press and hold the Sleep/Wake button on top of iPhone for a few seconds until a red slider appears, and then slide the slider. Then press and hold the Sleep/Wake button until the Apple logo appears.
It seems to be working fine now.
As is pointed out on this page of the Rails wiki, you need to do a few extra steps to run tests if you are using SQL Server.
(1) Create a unique index on each table. For example, if your table name is users, do this:
CREATE UNIQUE INDEX [users_index] ON [dbo].[users] ([id])
(2) [Thanks to the anonymous wiki author]Create a customized rake task for dumping the schema. Copy the following into mydb.rake and place it in appfolder/lib/tasks:
namespace :mydb do
task :migrate => :environment do
ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
Rake::Task["mydb:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
end
namespace :schema do
task :dump => :environment do
require 'active_record/schema_dumper'
File.open(ENV['SCHEMA'] || "db/schema.rb", "w") do |file|
ActiveRecord::Base.connection.instance_variable_get("@connection")["AutoCommit"] = false
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
end
end
end
Now you can use “rake mydb:schema:dump” to get a correct schema.rb file.
I have encountered some messy issues in using date_select in Rails. I have this Rails code in my view:
<%= date_select('task', 'due_date', :order => [:month, :day, :year],
:include_blank => true) %>
When the user fills in the month and day and leaves out the year, an exception is thrown (”1 error(s) on assignment of multiparameter attributes.”) It looks like ActiveRecord using the user’s month for the year (e.g. April is saved as 2004), and the user input for day is saved as the month. I was able to work around the problem by putting some extra code in the controller code - yuck, how ugly.
Found out there is a Rails patch (Ticket #8797) for this.
Had this problem a while ago on a web site (Linux, Apache, MySQL, PHP). It was difficult to track down and fix, so I thought I would post the solution here. Accented characters (like é) coming from text stored in the database were displaying as question marks. (Note — the character set in the database is ISO-8859-1 aka Latin-1.)
To track down the problem, I changed the character encoding manually using the browser to the aforementioned ISO-8859-1 (known in IE as Western European (ISO)). The page looked fine. So then the problem was getting the encoding to be that way by default. Using Chris Pederick’s Web Developer Toolbar for Firefox (an utterly essential tool), Information > View Response Headers, I saw that Apache was sending an HTTP header saying Content-Type text/html; charset=utf-8. Therefore, the browser was setting the encoding to Unicode. To fix it, I added this line to the .htaccess file:
AddDefaultCharset On
This sets Apache’s default charset to ISO-8859-1.
My next challenge was updating the .htaccess file on the web site. In the FTP program I normally use, WS_FTP, the .htaccess file was invisible (since the period at the beginning makes it a hidden file). The program didn’t even prompt to OK overwriting it, even when I did overwrite it! It was a lot easier to update it using FileZilla.