Netbeans, first impressions

I’ve always been a textmate user since I started web development with rails and OSX ( 2 years give or take ). Textmate is in my opinion a great text editor. Notably the best that I’ve ever used. with the recent release of Netbeans 6.8. I thought, why not give it a try, see what an IDE can offer that a text editor can’t.

Here’s what I think:

Pros:

  • Search is pretty fast when project indexing is complete. ( faster than textmate’s project search )
  • Its not very slow after startup ,its near textmate fast ( although textmate is one of the slowest text editors I’ve used especially if working on a big project )
  • A dark theme can be installed.
  • Most of the textmate code templates are available.
  • Code folding works as it should.
  • There are plugins to put in more features.
  • Code is analyzed for errors in realtime.
  • Code auto completion that works.
  • Its Free.

Cons:

  • tremendously slow when starting up.
  • eats up a lot of ram, and cpu.
  • doesn’t have a built in dark theme.

In addition, I changed some shortcut keys since I’m already used to textmate’s keybindings.

To conclude, I think I’m falling in love with netbeans. Especially with the search and autocomplete feature. Although its too early to really say that I’d stick to using it permanently. But I really like using it as my main editor.

Proper use of remote_function :with

This article is based on this blog post


<%= select_tag "content_type",  options_for_select(content_type_options),
 { :o nchange =>
    remote_function(
         :url => {:action => 'filter_by_content'},
         :with => 'Form.Element.serialize(this)')  } %>

This code will pass all the values from the serialized form. But I needed to define specific fields to pass along with the request and this wouldn’t work. I came up with.

<%= select_tag "content_type",  options_for_select(content_type_options),
 { :o nchange =>
    remote_function(
         :url => {:action => 'filter_by_content'},
         :with => "'key=' + Field.getValue('input_id')")  } %>

If you read thru the comments on the blog post mentioned above. this was already mentioned but the syntax was incorrect. it should be “‘key=’ + Field.getValue(‘input_id’)” not “{key : Field.getValue(‘input_id’)}”

I’m not entirely sure if the above syntax difference is due to the rails version I’m currently using ( 2.3.4 ) since its a 3 year old blog post.

Rails Caching Note : expiring cache when running your app with multiple slices

Note to self :

If you’re using fragment caching and you’re application is deployed to a hosting provider with multiple slices. don’t forget to define the location of the cache and store your cache in a location that all slices have access to. by default rails stores the cache in /tmp/cache , normally I would point it to RAILS_ROOT + tmp/cache

Here’s how to explicitly define the location of your cache:

Just need to define this in your environment.rb or create a file in the initializers directory.


ActionController::Base.fragment_cache_store = :file_store, "/path/to/cache/directory"

Some links about caching that I find very useful:

http://www.railsenvy.com/2007/2/28/rails-caching-tutorial

http://www.railsenvy.com/2007/3/20/ruby-on-rails-caching-tutorial-part-2

Using datetime_select together with a virtual field

I came across this problem just today, it cost me about 30 minutes to 1 hour just figuring out what I did wrong not to mention the time I spent trying to look for the solution. Luckily I stumbled upon this ticket. here Apparently this problem has already been reported and a patch has already been submitted over a year ago. But it hasn’t been pushed to rails core yet. Anyways to summarize the situation, heres how one can stumble into this problem:

Lets say you have a view which uses the date helper datetime_select like so:


<% form_for(:ticket, :url => tickets_path) do |f| %>
  	 <%= f.text_field :title -%>
  	 <%= f.text_field :description -%>
  	 <%= f.datetime_select :date_this_ticket_might_get_resolved -%>
<% end %>

And here’s a sample controller:


class TicketsController < ApplicationController

	def	create
		@ticket = Ticket.new(params[:ticket])
		@ticket.save
	end

end

And lastly the model:


class Ticket < ActiveRecord::Base

  	 def date_this_ticket_might_get_resolved=(val)
    	 	self.date_of_submission = Time.mktime( val[:year], val[:month], val[:day],
                                            val[:hour], val[:minute]) + 1.year
  	 end

  	 def date_this_ticket_might_get_resolved
    	 	self.date_of_submission + 1.year # add another year just to be sure
  	 end

end

You will get something like this error:


NoMethodError (You have a nil object when you didn't expect it!The error occurred while evaluating nil.klass):
	/vendor/rails/activerecord/lib/active_record/base.rb:2645:in `execute_callstack_for_multiparameter_attributes'
	/vendor/rails/activerecord/lib/active_record/base.rb:2644:in `each'
	/vendor/rails/activerecord/lib/active_record/base.rb:2644:in `execute_callstack_for_multiparameter_attributes'
	/vendor/rails/activerecord/lib/active_record/base.rb:2630:in `assign_multiparameter_attributes'
	/vendor/rails/activerecord/lib/active_record/base.rb:2375:in `attributes='

I was using Rails 2.1 with Ruby 1.8.6 , The patch can be found on this link, Just follow the instructions its just a one liner change on ActiveRecord::Base.

Return top