- Find Usages
- Rename Refactoring
- RHTML support
- Debugging (breakpoints, stepping etc. in RHTML files)
- Code completion
- Go to declaration
- Find Usages
- Rename
- Improved code completion - attributes, Rails migrations, models and views now include all the expected methods, etc.
- Enhanced RDoc rendering; embedded Ruby and RHTML code fragments are now syntax highlighted
- Debugger enhancements (global vars, watch view, locals view)
- Encoding support (projects now have an encoding property)
- Basic RSpec and ZenTest support (More Info), basic RJS support
- JRuby 1.0 is bundled
Tuesday, July 17, 2007
NetBeans IDE 6.0 M10 is out
Netbeans 6.0 M10 is out. There are many editing and debugging improvement for RHTML files. Here is the new feature sections for Ruby development.
Developing ROR using Emacs
I saw a few screencast on using Emacs to do ROR development but I was not able to setup emacs to try it out until I saw this five part series on setting up Emacs for Ruby on Rails development from Software bits and pieces.
http://sodonnell.wordpress.com/the-emacs-newbie-guide-for-rails/
After following guide step by steps I was able to get emacs up and running for developing ROR. Initially emacs started up with an error and it wasn't able to go into ROR mode. I found out I was missing inf-ruby which you can get it here. If you following the tutorial then put this file in your c:/emacs-22.1/includes/ directory. After putting the file there, everything works.
I found another site, credmp, also with instructions on how to setup emacs for ROR development. Ruby On Rails and Emacs It also list out the snippets that the emacs-rails supports.
http://sodonnell.wordpress.com/the-emacs-newbie-guide-for-rails/
After following guide step by steps I was able to get emacs up and running for developing ROR. Initially emacs started up with an error and it wasn't able to go into ROR mode. I found out I was missing inf-ruby which you can get it here. If you following the tutorial then put this file in your c:/emacs-22.1/includes/ directory. After putting the file there, everything works.
I found another site, credmp, also with instructions on how to setup emacs for ROR development. Ruby On Rails and Emacs It also list out the snippets that the emacs-rails supports.
Monday, July 02, 2007
Build FaceBook Application using Rails
Here are links to two blog articles on how to build FaceBook application using Rails.
From GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS:
fist in your facebook
From Liverail >> Rails with currents:
Tutorial on developing a Facebook platform application with Ruby On Rails
From GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS:
fist in your facebook
From Liverail >> Rails with currents:
Tutorial on developing a Facebook platform application with Ruby On Rails
Tuesday, June 19, 2007
Where to put the code
That is the question I ask all the time while developing in Rails. Should I put the code in the helper or in the model or in the controller itself. I guess I need to find some advance Rails reading material. On that note, Roby on Rails has a collection of links to making the model fat and the controller skinny. Put Your Controller on a Diet already!
After reading those blog posts, I am seeing myself putting some serious time in slim up my controllers. They are a little on the heavy side for sure.
After reading those blog posts, I am seeing myself putting some serious time in slim up my controllers. They are a little on the heavy side for sure.
Tuesday, May 08, 2007
observe_field and radio_button
I had a group of radio buttons that I wanted to trigger some action when one of the button is selected. I setup an observe_field for each radio button but it didn't work. You can't specify observe_field to monitor a group of radio buttons. It would only monitor the first button. Actually, let me clarify that statement. It would work the first time a user click on the button but then subsequence click would not register as something has changed. Apparently, it keeps the last value and when the radio button is selected again, the last value and the current value is the same. That result in a no change. I ended up using onclick with remote_function to trigger the change event.
This is what I had and it doesn't work.
This is what I had and it doesn't work.
<%= radio_button_tag 'ship_method', 'pickup', :checked => true -%> PickupThis is what I ended up with
<%= radio_button_tag 'ship_method', 'deliver' -%> Deliver
<%= observe_field 'ship_method_pickup',
:url => { :controller => 'checkout', :action => 'ship_method_select' },
:on => 'click', :with => 'method' -%>
<%= observe_field 'ship_method_deliver',
:url => { :controller => 'checkout', :action => 'ship_method_select' },
:on => 'click', :with => 'method' -%>
<input type="radio" name='ship_method' id='ship_method_pickup'
checked="checked" value="pickup"
onclick="<%=
remote_function(
:url => {:controller => 'checkout', :action => 'ship_method_select', :method => 'pickup'}
)-%>" />
Monday, May 07, 2007
How to pass a class or id to link_to_remote
This does seem like a really simple thing now that I figured out how to do it.
If you want to specify a fall back url for href instead of the default # you can put that in the html_options part also.
<%= link_to_remote 'Name',
{:url => {:controller => 'some_controller', :action =>'some_action', :id => some_id}},{ :class => 'some_class' }-%>
If you want to specify a fall back url for href instead of the default # you can put that in the html_options part also.
<%= link_to_remote 'Name',
{:url => {:controller => 'some_controller', :action => 'some_action', :id => some_id}},
{:class => 'some_class', :href => url_for({:controller => 'some_controller', :action => 'some_action', :id => some_id}) }-%>
Saturday, May 05, 2007
NetBeans IDE 6.0 M9 is out
I just saw that NetBeans 6 Milestone 9 was released. Go here to see all the changes for M9. There are many new features added for Javascript. You can edit embedded Javascript and CSS inside HTML/JSP. Of course, there are new features for Ruby editing.
Here is the list of changes for Ruby from the site.
Here is the list of changes for Ruby from the site.
Download and try it out for yourself.
- Advanced code editing: Code completion, Documentation Popup, Semantic highlighting (such as unused local variable coloring), Parameter Hints, Instant Rename, Goto Declaration, Live Code Templates, Mark Occurrences, Reformatting, Pair Matching, Smart Selection, Surround With
- Project support: Create and run files, run unit tests, run RSpec specifications, jump between files and their testcases, Ruby Gems support, ability to use any version of either JRuby or native Ruby
- Ruby Debugger, including Rails debugging - run/step, breakpoints, local variables, call stack, thread switching, balloon evaluation, etc. Support for native fast debugging.
- Ruby On Rails support: Code Generator wizard, Database Migrations, Rake Targets, Support for generator plugins, Jump between Action and View, RHTML highlighting
Sunday, April 01, 2007
NetBeans IDE 6.0 M8 is out
I just installed NetBeans IDE 6.0 M8 and noticed that you can start and stop WEBrick within NetBeans now. Before this release, you would have to kill the java task from the task manager which was a pain. I actually didn't use WEBrick within the ide because of this problem. Instead, I just run it from the command line using the native ruby interpreter instead of jruby.
Before I was able to use the WEBrick instance started by NetBeans, I need to setup the project to use the jdbc adapter for MySQL. Since I didn't really bother reading much instruction, I encountered quite a few problems.
Here are the steps I used to get everything working.
1. Modify environment.rb and add these lines in right before Rails::Initializer:
2. Modify database.yml to use the jdbc adapter. Of course, instead of test_development, you put your own database name there.
3. Download the JDBC driver for MySQL.
Download Connector/J 5.0
Unzip or untar the archive and copy mysql-connector-java-5.0.5-bin.jar to your jruby-0.9.8\lib.
You can find your jruby-0.9.8 directory under
C:\Documents and Settings\<your username>\.netbeans\
I found this step to be quite important because adding the driver to CLASSPATH did not work for me.
NetBeans also exposed more rake tasks than before.
Before I was able to use the WEBrick instance started by NetBeans, I need to setup the project to use the jdbc adapter for MySQL. Since I didn't really bother reading much instruction, I encountered quite a few problems.
Here are the steps I used to get everything working.
1. Modify environment.rb and add these lines in right before Rails::Initializer:
if RUBY_PLATFORM =~ /java/
require 'rubygems'
RAILS_CONNECTION_ADAPTERS = %w(jdbc)
end
Rails::Initializer.run do |config|
2. Modify database.yml to use the jdbc adapter. Of course, instead of test_development, you put your own database name there.
development:
adapter: jdbc
driver: com.mysql.jdbc.Driver
username: root
password: password
url: jdbc:mysql://localhost:3306/test_development
3. Download the JDBC driver for MySQL.
Download Connector/J 5.0
Unzip or untar the archive and copy mysql-connector-java-5.0.5-bin.jar to your jruby-0.9.8\lib.
You can find your jruby-0.9.8 directory under
C:\Documents and Settings\<your username>\.netbeans\
I found this step to be quite important because adding the driver to CLASSPATH did not work for me.
NetBeans also exposed more rake tasks than before.
Wednesday, March 21, 2007
How to use migration
Yavor Ivanov over at rubycorner.net started a mini series on Rails migration. So far there is one article and I already learned a few things that I didn't know.
How to use Rails Migrations - Part I
I created a table with :created_at column as :null => false but I didn't define the default value so I was having problem with specifying the datetime in my test fixture.
I solved that problem by putting this in my test fixture:
How to use Rails Migrations - Part I
I created a table with :created_at column as :null => false but I didn't define the default value so I was having problem with specifying the datetime in my test fixture.
I solved that problem by putting this in my test fixture:
created_at: <%= DateTime.now.strftime('%y-%m-%d %H:%M:%S') %>What I really should have done is created the column like this.t.column :created_at, :datetime, :default => Time.now
Tuesday, March 20, 2007
Ruby on Rails Caching
Gregg Pollack over at Rails Envy posted two articles on Ruby on Rails Caching. If you have performance issue, you might want to check them out.
Ruby on Rails Caching Tutorial - Part 1
Ruby on Rails Caching Tutorial - Part 2
Ruby on Rails Caching Tutorial - Part 1
Ruby on Rails Caching Tutorial - Part 2
Monday, March 19, 2007
Ruby on Rails screencasts
I found this website, Railscasts, that has free Ruby on Rails screencasts. So far, there are 7 screencasts and they are posted pretty regularly.
Friday, March 16, 2007
Acts As State Machine plugin
I just finished reading Bruce Tate article, Crossing borders: Extensions in Rails (The anatomy of an acts_as plug-in), where he mentioned the acts_as_state_machine plugin for Rails. If you ever have model with known transition paths between different states then this plugin will be a great help to you.
Here is an article, The Complete Guide to Rails Plugins: Part 1, on Nuby on Rails showing how to install and create Rails plugin.
And finally, you can go to the acts_as_state_machine plugin's author blog, Acts As State Machine, to see where to download and how to use the plugin.
Here is my example of how to use the plugin to keep track of a light fixture with three state (off, low, and high).
Here is an article, The Complete Guide to Rails Plugins: Part 1, on Nuby on Rails showing how to install and create Rails plugin.
And finally, you can go to the acts_as_state_machine plugin's author blog, Acts As State Machine, to see where to download and how to use the plugin.
Here is my example of how to use the plugin to keep track of a light fixture with three state (off, low, and high).
# The Migration class for light
class CreateLights < ActiveRecord::Migration
def self.up
create_table :lights do |t|
t.column :name, :string
t.column :status, :string
end
end
def self.down
drop_table :lights
end
end
# The Model for light
# A simple transition for a light with three states, (off, low, high)
#
# +---------+ switch +---------+ switch +---------+
# | off |-------->| low |-------->| high |
# +---------+ +---------+ +---------+
# ^ |
# |_________________________________________|
#
class Light < ActiveRecord::Base
acts_as_state_machine :initial => :off, :column => 'status'
state :off
state :low
state :high
event :switch do
transitions :from => :off, :to => :low
transitions :from => :low, :to => :high
transitions :from => :high, :to => :off
end
end
-------------------------
Here is a sample run:
>> l = Light.create
=> ...
>> l.current_state
=> :off
>> l.switch!
=> nil
>> l.current_state
=> :low
>> l.switch!
=> nil
>> l.current_state
=> :high
>> l.switch!
=> nil
>> l.current_state
=> :off
Thursday, March 15, 2007
Tips for working with Test Fixtures in Rails
I have a requirement in my migration script that created_at column can not be null.
t.column :created_at, :datetime, :null => false
This cause the Test Fixtures loading to fail. My first attempt to remedy this problem was like this.
created_at: <%= DateTime.now %>
This did not work since the date time format is incorrect. The correct format is year-month-day hour:minute:second.
So, I changed it to
created_at: <%= DateTime.now.strftime('%y-%m-%d %H:%M:%S') %>
and it works.
I don't know if there is a better way to do this but this works for me. Since I went around looking for the solution, I decided to write it down.
t.column :created_at, :datetime, :null => false
This cause the Test Fixtures loading to fail. My first attempt to remedy this problem was like this.
created_at: <%= DateTime.now %>
This did not work since the date time format is incorrect. The correct format is year-month-day hour:minute:second.
So, I changed it to
created_at: <%= DateTime.now.strftime('%y-%m-%d %H:%M:%S') %>
and it works.
I don't know if there is a better way to do this but this works for me. Since I went around looking for the solution, I decided to write it down.
Wednesday, March 14, 2007
Validate a number is an integer and within a certain range
Use validates_numericality_of , and validates_inclusion_of to check that a number is an integer and within a certain range.
For example:
You only want to allow people to enter a number between 21 and 30. Here is how you would do it.
validates_numericality_of :n, :only_integer => true, :message => "can only be whole number."
validates_inclusion_of :n, :in => 21..30, :message => "can only be between 21 and 30."
For example:
You only want to allow people to enter a number between 21 and 30. Here is how you would do it.
validates_numericality_of :n, :only_integer => true, :message => "can only be whole number."
validates_inclusion_of :n, :in => 21..30, :message => "can only be between 21 and 30."
Tuesday, March 13, 2007
Ruby on Rails Quick Reference
I was looking for a way to update my rails application to rails 1.2.3 when I found this guide, Ruby on Rails Quick Reference. It has descriptions to many frequently use rails features.
rake rails:update is how you update your rails application.
Found a cheat sheet with a great deal of information:
Ruby on Rails 1.1 Reference
rake rails:update is how you update your rails application.
Found a cheat sheet with a great deal of information:
Ruby on Rails 1.1 Reference
Drop Derby and goes back to MySql
After my rant yesterday about Derby not supporting column rename, I checked ActiveRecord-JDBC document for Derby and column_rename is not one of the supported feature.
Here is the list of databases and the level of support taken from the document.
I did notice one little problem with Netbeans today. The "Generate" menu item disappeared from the menu for some reason. I closed and reopened Netbeans but that didn't do anything. Finally, I closed the project, reopen it and the Generate menu item came back. It only happened once. I don't remember what I did to cause the problem though.
Here is the list of databases and the level of support taken from the document.
- MySQL - Complete support
- PostgreSQL - Complete support
- Oracle - Complete support
- Microsoft SQL Server - Complete support except for change_column_default
- DB2 - Complete, except for the migrations:
- change_column
- change_column_default
- remove_column
- rename_column
- add_index
- remove_index
- rename_table
- FireBird - Complete, except for change_column_default and rename_column
- Derby - Complete, except for:
- change_column
- change_column_default
- remove_column
- rename_column
- HSQLDB - Complete
I did notice one little problem with Netbeans today. The "Generate" menu item disappeared from the menu for some reason. I closed and reopened Netbeans but that didn't do anything. Finally, I closed the project, reopen it and the Generate menu item came back. It only happened once. I don't remember what I did to cause the problem though.
Monday, March 12, 2007
Derby does not support renaming column
-- rename_column(:users, :username, :user_name)
rake aborted!
rename_column is not implemented
Opps, I hit another snag when trying to rename username to user_name. Apparently, Derby does not allow renaming of column. I wiped out the database and started over but that is not a practical way to do thing going forward. I think my experiment with Derby is coming in an end here. I wonder why Sun is endorsing a database that is missing such fundamental feature. I don't remember using a database that does not support renaming of column. I guess there is a first for everything.
Now, I regretted that I read, "If You Thought Rails Development Was Fast Before...". I wouldn't have tried Derby without reading that article. It should be renamed to "If You Thought Rails Development Was Fast Before... Here Is How To Slow Yourself Down". I know it is a cheap shot but that article really make me think that I would be more productive using Derby as my development database.
rake aborted!
rename_column is not implemented
Opps, I hit another snag when trying to rename username to user_name. Apparently, Derby does not allow renaming of column. I wiped out the database and started over but that is not a practical way to do thing going forward. I think my experiment with Derby is coming in an end here. I wonder why Sun is endorsing a database that is missing such fundamental feature. I don't remember using a database that does not support renaming of column. I guess there is a first for everything.
Now, I regretted that I read, "If You Thought Rails Development Was Fast Before...". I wouldn't have tried Derby without reading that article. It should be renamed to "If You Thought Rails Development Was Fast Before... Here Is How To Slow Yourself Down". I know it is a cheap shot but that article really make me think that I would be more productive using Derby as my development database.
Sunday, March 11, 2007
Using Rails migration with Netbeans 6.0 M7
I hit a temporary road block while following the steps from this article, If You Thought Rails Development Was Fast Before.... I wanted to use migration instead of sql to create the table in the database. After using the generator to create the migration file, I couldn't figure out how to call the db:migrate task in rake. There is no obvious way to call it from Netbeans 6 itself. I look everywhere but I couldn't find anything. I look in jruby-0.9.2 directory and rake is there but there is no bat file to call it. So, I created a bat file to call rake then execute rake db:migrate directly from the command prompt. That did the trick.
Here is the link to a Derby tutorial on how to create a new database in Derby from Netbeans.
Derby Tutorial
Here is the link to a Derby tutorial on how to create a new database in Derby from Netbeans.
Derby Tutorial
Thursday, March 08, 2007
OpenID and Rails
Ruby Inside has a collection of links to discusses and resources on OpenID and Rails. At the bottom, there is a link to Bernie Thompson's screencast and additional OpenId resources.
OpenID for Rails - Bernie Thompson
8 OpenID Resources for Rails Developers - Ruby Inside
OpenID for Rails - Bernie Thompson
8 OpenID Resources for Rails Developers - Ruby Inside
Wednesday, March 07, 2007
Rails' validators
Every wonder how to use all those validators (validates_presence_of, validates_uniqueness_of, validates_size_of, validates_acceptance_of, etc..), in Rails? Head over to Juixe TechKnow and read Rails Model Validators. The author has simple samples and explanations for those and a few more.
Subscribe to:
Posts (Atom)