What a morning!
A user kindly reported that he couldn't log in to FilmAmora using IE7. IE6 worked, FireFox worked. Safari worked.
IE7 (for me) was coming up first with the 'there is insecure content on this page do you wish to show it?' (the login in page is under https). Clicking yes or no had the same result: the page would flash but then IE7 reported that it couldn't show the page. (It should have, it turns out, said 'I am choosing not to show the page').
The issue was that insecure content. For me, specifically it was the statcounter call. But your issue may be other calls. Anyway, I removed all calls to anything outside of my domain and that seems to have fixed it!
Thursday, 27 November 2008
Monday, 3 November 2008
unfuddle
I use unfuddle as a git host and bug tracking, etc service. But, because I have so many projects on the go I ran into this problem where you can only have an ssh key in ONE account on unfuddle. So, I wrote to the support guys and asked them how to handle multiple accounts from one machine.
Here is their response:
The easiest way to deal with need multiple keys for multiple accounts is to actually just create them using different filenames in your ~/.ssh/ directory. For instance, if you have 2 accounts, "account1" and "account2", you would want to run "ssh-keygen -t rsa" twice, each time specifying a different filename:
~/.ssh/unfuddle_account1_id_rsa
~/.ssh/unfuddle_account2_id_rsa
Now, by default, ssh will use the file ~/.ssh/id_rsa when connecting to a remote server. As neither of your keys is in this file, you must tell SSH (not git) which private keyfile to use when connecting to each account. This is done using the SSH config file.
For instance, create or edit a file named .ssh/config with the following contents:
Host account1.unfuddle.com
User git
IdentityFile ~/.ssh/unfuddle_account1_id_rsa
Host account2.unfuddle.com
User git
IdentityFile ~/.ssh/unfuddle_account2_id_rsa
I have followed this model for my own accounts (of which I have many) and it has worked perfectly. I hope this helps you as well.
Here is their response:
The easiest way to deal with need multiple keys for multiple accounts is to actually just create them using different filenames in your ~/.ssh/ directory. For instance, if you have 2 accounts, "account1" and "account2", you would want to run "ssh-keygen -t rsa" twice, each time specifying a different filename:
~/.ssh/unfuddle_account1_id_rsa
~/.ssh/unfuddle_account2_id_rsa
Now, by default, ssh will use the file ~/.ssh/id_rsa when connecting to a remote server. As neither of your keys is in this file, you must tell SSH (not git) which private keyfile to use when connecting to each account. This is done using the SSH config file.
For instance, create or edit a file named .ssh/config with the following contents:
Host account1.unfuddle.com
User git
IdentityFile ~/.ssh/unfuddle_account1_id_rsa
Host account2.unfuddle.com
User git
IdentityFile ~/.ssh/unfuddle_account2_id_rsa
I have followed this model for my own accounts (of which I have many) and it has worked perfectly. I hope this helps you as well.
Thursday, 16 October 2008
Creating a summary
I have an app that has rows of statistics. We wanted to create summaries of arbitrary rows.
This method seems to work:
This method seems to work:
def self.create_summary_row(array)
unless array.blank?
klazz = array.first.class
sum_stat = klazz.new
array.each do |line|
if line.is_a?(klazz)
line.attributes.each do |k,v|
unless v.nil? || v.is_a?(Time) || v.is_a?(Date)
if sum_stat[k].nil?
sum_stat[k] = v
else
sum_stat[k] += v
end
end
end
end
end
sum_stat
end
end
Monday, 29 September 2008
ec2onrails
This is so great - goodbye other hosting companies that can't compete!
Amazon has hosting facilities known as ec2 (elastic compute cloud). You pay by the hour ($.10 for a small installation). That works out to around $70/month. But, the power you get is much better than your average hosting.
Paul Dowman has released a great ec2 instance called ec2onrails that can get your rails app up and running on ec2 in about 30 minutes. I am now using it for FilmAmora as well as for another client.
It is awesome!
One thing I discovered today was the sweet built-in support for cron jobs. Write a script and plop it in your app's script directory. Call it hourly, daily or weekly (perhaps monthly? I didn't check). This script will get run automatically by an already existing cron job! No need to figure out those silly cron settings. Very cool!
I highly recommend it. FilmAmora is running much much better on it than on the old hosting (where I had to restart it every day just to hopefully have enough memory to run 2 mongrels).
Amazon has hosting facilities known as ec2 (elastic compute cloud). You pay by the hour ($.10 for a small installation). That works out to around $70/month. But, the power you get is much better than your average hosting.
Paul Dowman has released a great ec2 instance called ec2onrails that can get your rails app up and running on ec2 in about 30 minutes. I am now using it for FilmAmora as well as for another client.
It is awesome!
One thing I discovered today was the sweet built-in support for cron jobs. Write a script and plop it in your app's script directory. Call it hourly, daily or weekly (perhaps monthly? I didn't check). This script will get run automatically by an already existing cron job! No need to figure out those silly cron settings. Very cool!
I highly recommend it. FilmAmora is running much much better on it than on the old hosting (where I had to restart it every day just to hopefully have enough memory to run 2 mongrels).
Friday, 15 August 2008
secure forms
One thing I struggled with in RoR was creating forms that submitted to https. So I ended up writing a couple of helpers:
and
The should be simple replacements for form_for and form_tag. Now, I have to admit I wrote these when I was using Rails 1.2.5, so there might be some things in 2.x that make these redundant, but, they work for me.
The only caveat is that if you are doing a form where you are not passing in the action, just the object e.g
Then you are going to have to supply the actions. I am looking into this now, and I might rewrite this post if I sort it out!
def secure_form_for(record_or_name_or_array, *args, &proc)
unless RAILS_ENV == 'production'
url_options = {}
else
url_options = {:protocol => 'https://', :only_path => false }
end
options = args.last.is_a?(Hash) ? args.pop : {}
if !options[:url].nil?
options[:url] = url_options.merge options[:url]
else
options[:url] = url_options
end
return form_for(record_or_name_or_array, options, &proc)
end
and
def secure_form_tag(*args, &proc)
logger.debug("secure_form_tag args #{args.inspect}")
unless RAILS_ENV == 'production'
url_options = {}
else
url_options = {:protocol => 'https://', :only_path => false }
end
options = args.last.is_a?(Hash) ? args.pop : {}
if !options[:url].nil?
options[:url] = url_options.merge options[:url]
else
options[:url] = url_options
end
logger.debug("secure_form_tag options #{options.inspect}")
return form_tag(options, &proc)
end
The should be simple replacements for form_for and form_tag. Now, I have to admit I wrote these when I was using Rails 1.2.5, so there might be some things in 2.x that make these redundant, but, they work for me.
The only caveat is that if you are doing a form where you are not passing in the action, just the object e.g
<% form_for @object do %>
Then you are going to have to supply the actions. I am looking into this now, and I might rewrite this post if I sort it out!
Labels:
secure forms,
views
Saturday, 26 July 2008
xml_hidden plugin
Recently I've been investigating the steps needed to open up FilmAmora's API to the outside world. That means supplying xml data so people can do what they want with it.
But I didn't want sensitive data in models to be exposed in the xml. And I also am too lazy to write custom to_xml methods for everything.
So I wrote a plugin call xml_hidden That lets you set something on the class to hide certain attributes from xml output.
Now whenever I output a film to xml those values can't be seen.
But I didn't want sensitive data in models to be exposed in the xml. And I also am too lazy to write custom to_xml methods for everything.
So I wrote a plugin call xml_hidden That lets you set something on the class to hide certain attributes from xml output.
class Film < ActiveRecord::Base
attr_xml_hidden :acquiring_url, :id, :created_at
end
Now whenever I output a film to xml those values can't be seen.
Labels:
plugins,
xml_hidden
Sunday, 20 July 2008
Escaping for JavaScript
Recently I've started to use the most excellent Prototip2 for doing sexy tooltip stuff. It works a treat.
The only problem I have had is that some of the things I want to put into the tips have single quotes in them (e.g Bob's Team). I was surprised to find that Rails doesn't (as far as I could find) have a handy dandy way of making strings JS friendly. So I whipped up this extention to Erb::Util.
I hope some of you find it useful. It will escape single quotes and as an added bonus it also does the html escaping so you only have to make one call.
I put this into an initializer.
You can then call it from your views like this:
The only problem I have had is that some of the things I want to put into the tips have single quotes in them (e.g Bob's Team). I was surprised to find that Rails doesn't (as far as I could find) have a handy dandy way of making strings JS friendly. So I whipped up this extention to Erb::Util.
I hope some of you find it useful. It will escape single quotes and as an added bonus it also does the html escaping so you only have to make one call.
class ERB
module Util
def js_escape(str)
h(str.gsub(/[']/, '\\\\\''))
end
alias js js_escape
module_function :js
module_function :js_escape
end
end
I put this into an initializer.
You can then call it from your views like this:
<%=js team.name%>
Subscribe to:
Posts (Atom)