Archive for September, 2008

http and https with different urls in rails

I wanted to do the following on my site:

http://www.cadechristian.com and https://secure.cadechristian.com

I ran in to the problem that the cookie was not valid on BOTH domains and I search for the longest time before I found this solution.

What I found was to put this in the environmnet.rb file: (I’m on rails 2.1)

config.action_controller.session = {
:session_domain => ‘.cadechristian.com’,
:session_key => ‘xxxxxxxxxxxxxxxxxxx’,
:secret => ‘xxxxxxxxxxxxxxxxxxx’
}

I had some issues testing this on my local development environment since I was using just cadechristian as the hostname. The cookie host NEEDS to have the . and then a domainname.com. (minimum two levels)

.something.local is valid but .something is not.. The first DOT is very important for it to work.

Now I installed the ssl_requirement plugin and hardcoded the code where it does the redirect to SSL_HOSTNAME and NONE_SSL_HOSTNAME which I set in my development.rb/production.rb…

Works great….

Advertisements

Building a site map in Ruby on Rails…

I needed an automated sitemap process for the http://www.cadechristian.com website and here is what I managed to create…
route.rb:

map.sitemap ‘sitemap.xml’, :controller => ‘sitemap’, :action => ‘sitemap’

robots.txt:

Sitemap: http://www.cadechristian.com/sitemap.xml

sitemap controller:

def sitemap
@model1 = Page.find(:all)
@model2 = Page.find(:all)
render :layout => false
end

/app/view/sitemap/sitemap.builder:

@home_url = ‘http://www.cadechristian.com’

xml.instruct!
xml.urlset :xmlns => ‘http://www.sitemaps.org/schemas/sitemap/0.9’ do

# Add static Urls
%w( / /url1 /url2 /url3 ).each do |url|
xml.url do
xml.loc @home_url + url
xml.lastmod Time.today.xmlschema
xml.priority 1
end
end

@model1.each do |model|
xml.url do
xml.loc @home_url + model_path(model)
xml.lastmod product.updated_at.xmlschema
xml.priority 0.9
end
end

@model2.each do |model|
xml.url do
xml.loc @home_url + model_path(model)
xml.lastmod product.updated_at.xmlschema
xml.priority 0.9
end
end
end

That removes the need to update my sitemap.xml file when we add products and other static resources 🙂

You could also create a ruby script or some hook that runs this code:

require ‘net/http’
require ‘uri’
include ActionController::UrlWriter

sitemap_uri = ‘www.cadechristian.com/sitemap.xml’
escaped_sitemap_uri = URI.escape(sitemap_uri)

%w( submissions.ask.com http://www.google.com ).each do |engine|
Net::HTTP.get(engine, ‘/ping?sitemap=’ + escaped_sitemap_uri)
end
Net::HTTP.get(‘webmaster.live.com’, ‘/ping.aspx?siteMap=’ + escaped_sitemap_uri)

This would ping the search engines and you are done…

mod_mem_cache.c:591: undefined reference to `ap_cache_cacheable_hdrs_out’

If you are getting this error, it’s because you’ve included the ‘--enable-mem-cache‘ flag, but not the ‘--enable-cache‘ one. You need both.

enable-disk-cache also needs the same enable-cache switch to work.