NoobOnRails

Ruby on Rails tips, tricks and hints for the aspiring rails hero.



Tuesday, August 29, 2006

Adding user support to the acts_as_taggable plugin


I was going to write this huge post on how to do this but it looks like I don't need to. SlashDotDash has a post up on how to add user support to acts_as_taggable and it looks mighty fine to me so instead of duplicating efforts...go here! The problem with this is that when a user edits the tags, they could potentially delete all of the tags for that item. I could work on a fix for this unless someone else has one they can post?

Monday, August 28, 2006

Best Rails editor for the pc


I just wanted to put this post up because these guys don't seem to get too much love in the community and I think they deserve some more. RadRails has, in my experience, been the best development environment to use when building Rails sites in a Windows environment. Why do I like it so? Besides the obvious organizational benefits that come from migrating from Notepad, I can easily configure it to run either a mongrel or webrick server (I haven't tried lightty on Windows), plus I can easily switch my perspective over to a view of my database or a view of my SNV repository (amongst others) and with the SVN tools being, I can just keep better track of changes. For me, it's just awsome. That could have something to do with me being relatively new to the whole IDE-ish world of development but I know what I likes, and I likes me some RadRails.

Are there any other notable IDE/editors that are Rails friendly that I should try? The ones I've seen don't compare feature wise to RadRails just yet.

Acts as Taggable gem springs back to life


Apparently Obie Fernandez is caught up writing a book so he passed the acts_as_taggable gem hat on to Dirk Elmendorf. He's already applied some useful changes and even made the gem safer to use (preveted SQL injection attacks). I have an acts_as_taggable plugin article cooking but now I'm thinking I may switch it over to the gem instead of the plugin. I'm not sure though, I'll tinker with it and whatever seems more benefical I'll use. Either way, it's good to see this project get picked back up again.

Monday, August 21, 2006

Redirecting with Mongrel


This took me a minute to figure but with the great folks at Mongrel support (ie Zed), it was a piece of cake. This is the script I stuck in a file called, mongrel.conf in my railsapp/log folder on my production server.


class RedirectHost < Mongrel::HttpHandler

def process(request, response)
if request.params["HTTP_X_FORWARDED_HOST"] == "DOMAIN.com"
response.start(302,true) do |head, body|
head["Location"] = "http://www.DOMAIN.com/"
head["Content-type"] = "text/html"
body.write("Please go here instead: www.DOMAIN.com")

end
end
end

end

uri "/", :handler => RedirectHost.new, :in_front => true



What this script is basically saying is that if the incoming HTTP request begins with just "domain.com", redirect it to "http://www.domain.com". In my if statement, I had to use request.params["HTTP_X_FORWARDED_HOST"] becuase I'm on a shared host which puts me behind a proxy. If you try this script and it's not working, stick

puts request.params.inspect

under the body.write line and above that first end, save it, stick it on your server, restart mongrel
and try hitting your site again. It still won't work, but you'll get some more information in your
mongrel.log file. From that extra info, you should be able to see if you need to use
"HTTP_X_FORWARDED_HOST" or just "Host". You can see my redirecting in action over at http://cookmor.com
(that'll redirect to http://www.cookmor.com)


UPDATE: I thought i would mention how you start mongrel to load that script. The mongrel.conf sits in your railsapp/log folder so, from your RailsApp folder, start mongrel with with this:

mongrel_rails start -e production -p YOURDESIREDPORT -d -S log/mongrel.conf