Official: Ruby on Rails Support on Microsoft IIS with FastCGI Extension
October 10th, 2007
Microsoft has just announced full FastCGI support for it's websever software - Internet Information Services (IIS). Though primarily a PHP announcement (the FastCGI Extension was developed by Microsoft in partnership with Zend), it does offer Ruby developers a glimmer of hope for running Ruby on Rails on Windows servers.
"By supporting the open standard, Microsoft has made it possible for PHP and other CGI compliant languages to be hosted efficiently and effectively on Windows Server 2003 and IIS."
The important part here for Rails developers is in the middle of that statement - and other CGI compliant languages. We find from reading the Using FastCGI to Host PHP Applications on IIS 6.0 and IIS 5.1 guide on the same website under the "What is FastCGI?" heading that:
"The IIS FastCGI support enables IIS to host normal CGI programs like PHP, or Ruby On Rails, using the FastCGI protocol, offering high-performance and stability for production deployment of such application frameworks."
This new FastCGI Extension will be available for webhosts to use on older versions of IIS 6 and 5.1, so there will be no excuse anymore for Windows hosts not to support Ruby on Rails.
"This FastCGI Extension release is supported on IIS 6 on Windows Server 2003 for a fully scalable production environment and on IIS 5.1 on Windows XP in order to support developers who build their Web applications on Windows client machines."
At the end of the article lies the true gem:
"Looking ahead, betas of Windows Server 2008, already include the FastCGI Extension as a completely integrated feature of Internet Information Services IIS 7.0 (IIS7)."
This means the capability to run Ruby and Ruby on Rails (via the FastCGI extension) will be available on IIS out of the box, in all future versions. May Ruby on Rails developers around the world rejoice.
Raising errors in controllers
September 21st, 2007
1 2 3 4 5 6 7 |
def create @book = Book.new params[:book] @book.save! flash[:notice] = 'Book was successfully created.' redirect_to @book end |
1 2 3 4 5 6 7 8 |
private
def rescue_action(exception)
exception.is_a?(ActiveRecord::RecordInvalid) ? render_invalid_record(exception.record) : super
end
def render_invalid_record(record)
render :action => (record.new_record? ? 'new' : 'edit')
end
|
1 2 3 4 5 6 7 |
def update @book = Book.find params[:id] @book.update_attributes! params[:book] flash[:notice] = 'Book was successfully updated.' redirect_to @book end |
render :action => (record.new_record? ? 'new' : 'edit') |
how to undo script/generate migration
September 17th, 2007
Rspec and autotest
September 17th, 2007
I thought I’d mention this briefly as rspec is becoming a very popular way to test. I was manually running my tests until I was recently pointed in the direction of auto-test with spec_server. This significantly increases the feedback loop for when your tests pass and fail; increasing productivity exponentially. The steps are as follows:
Install ZenTest:
sudo gem install ZenTest
Install rspec for rails:
http://rspec.rubyforge.org/documentation/rails/install.html
Open up a terminal and open run script/spec_server from the root of your rails application. Then open up another terminal and run autotest -rails (also inside of the root of the rails application). Edit a spec to make it fail, save it and watch autotest tell you it failed! I know you can get this to work with growl (I’m on Ubuntu so I don’t use growl). If someone with OS X experience can comment on how to get growl integrated and perhaps provide an alternative for linux, I will post it up.
Adding type to a table in migrations
August 28th, 2007
script/generate migration add_type_to_users
in my terminal and it automatically generated a migration with the code generated for me.
1 2 3 4 5 6 7 8 9 |
class AddTypeToUsers < ActiveRecord::Migration def self.up add_column :users, :type, :type, :null => :no?, :default => :maybe? end def self.down remove_column :users, :type end end |
Am I being n00b, or is this a new feature in edge rails? Does this work for columns not reserved for rails?
UPDATE:
On further inspection, this is a new thing in edge rails and it does work for other columns. While running the following:
script/generate migration add_name_to_users
I got the following migration:
1 2 3 4 5 6 7 8 9 |
class AddNameToUsers < ActiveRecord::Migration def self.up add_column :users, :name, :type, :null => :no?, :default => :maybe? end def self.down remove_column :users, :name end end |
script/generate migration add_name_string_to_users
1 2 3 4 5 6 7 8 9 |
class AddNameStringToUsers < ActiveRecord::Migration def self.up add_column :users, :name_string, :type, :null => :no?, :default => :maybe? end def self.down remove_column :users, :name_string end end |
script/generate migration add_name_and_date_to_users
and got the following:
class AddNameAndDateToUsers < ActiveRecord::Migration
def self.up
add_column :users, :name_and_date, :type, :null => :no?, :default => :maybe?
end
def self.down
remove_column :users, :name_and_date
end
end
It seems that the implementation is pretty primitive. Obviously I'm using a bad approach as I should be looking at the source to see if any additional implementation does exist without my knowing, but I was hoping that the most intuitive thing for me would implemented already. I think it would be cool to see this syntactic sugar get more advanced. Comments? Opinions?
NOTE: The code that is generated by the migration does not work automatically. You have to change the stubbed symbols placed inside the migration to whatever you need. It's more of a guide than a performance enhancer (which IMO think that it should be both).
Importing PHPMyAdmin export files using migrations
August 27th, 2007
1 2 3 4 5 6 7 8 9 10 |
def self.up @first_query = true sql_file = File.dirname(__FILE__) + "/../some_crazy_file.sql" IO.readlines(sql_file).join.split(/;\nINSERT INTO /).each do |q| q = "INSERT INTO " + q unless @first_query execute q @first_query = false end end |
UPDATE: My friend Brandon, who chose not to comment on this blog post (shame on him!) said that running the sql file in command line could work as a more elegant solution there. The only problem I have with this approach is whether or not the rake task fails if the operation fails. So you code would like like this:
1 2 3 |
def self.up result = `mysql db_name < some_crazy_file.sql` end |
The only thing left is to make sure that result returns a favorable result, and if it doesn't then fail the migration. I'm not exactly sure how to do this (to busy to investigate). Any takers?
Anvil: The Ruby Application Framework
August 13th, 2007
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
anvil "Hammer" do |app| app.frame "Hammer", "Hammer", :maximize => true do |frame| # Create Menu Bar frame.menu_bar do |menu_bar| # File Menu menu_bar.menu "&File" do |item| item.add(:new) item.add(:open) item.separator item.add(:save) item.separator item.add(:preview) item.add(:print) item.separator item.add(:close) item.add(:quit) end # Edit Menu menu_bar.menu "&Edit" do |item| item.add(:undo) item.add(:redo) item.separator item.add(:cut) item.add(:copy) item.add(:paste) item.add(:delete) item.separator item.add(:selectall) item.separator item.add(:preferences) end # Search Menu menu_bar.menu "&Search" do |item| item.add(:find) item.add(:replace) end # Help Menu menu_bar.menu "&Help" do |item| item.add(:about) end end frame.text_control :size => { :width => 100, :height => 200 } frame.create_status_bar(2) frame.set_status_text("Hammer World!", 0) end end |
RSpec and RESTful Polymorphic Url Helpers
August 10th, 2007
1 2 3 4 5 6 7 8 |
ActionView::TemplateError in 'Edit Artist Page should render the edit artist form'
label_artist_url failed to generate from {:action=>"show", :controller=>"artists"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: ["labels", :label_id, "artists", :id] - are they all satisfied?
On line #3 of app/views/artists/edit.rhtml
1: <h1>Editing artist</h1>
2:
3: <% form_tag label_artist_path, :method => :put do %>
|
label_artist_path(@label, @artist) |
(class << @controller; self; end).send :include, ActionView::Helpers::UrlHelper |
1 2 3 4 5 6 7 8 9 |
ActionView::TemplateError in 'Edit Artist Page should render the edit artist form'
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.url_for
On line #3 of app/views/artists/edit.rhtml
1: <h1>Editing artist</h1>
2:
3: <% form_tag label_artist_path, :method => :put do %>
|