Category Archives: Ruby on Rails

Continuos Integration


Recently we did the setup for Continuos Integration for our apps at Sapnasolutions. As you might know Continuos Integration is one of the major practices of XP. We were evaluating some of the CI tools like CruiseControl and Integrity and Hudson. Though I still have not tried Hudson which everybody is recommending, our purpose has been served well by Integrity + report card combo.

mmm… actually in theory I liked CC better then integrity as CC has out of the box support for metric_fu. But for Integrity one have to setup the report_card site. Also as far as I got the benefit of Integrity is just that in it you can identify which commit exaclty has broken the build as it runs build on each commit whereas CC works on push. But the Integrity+Report card takes much time as compared to CC to setup.

For us CC coudnt become an option as on our server where we have Ruby Enterprise Edition whose default path is different then normal ruby CC is not able to pick the already installed gems. So when I try to run metric_fu rake task metrics:all it does not identify any of the required gems(rcov reek roodi flay flog)…Though the task run fine in the repo on server…

Anyways will keep you updated on any other tool (specially Hudson if we can have java on server) I try…Till then let Sapnasolutions build their dreamz in Integrity :)


Merb Slices in Rails 3: The goodies coming along more efficiently


As most of you already know Merb Slices are the mix of merb app and plugin, which carries feature goodies of both. Its the part of an app which can itself work as an application and can be incorporated in any other merb application. For example remember Rails engines. It gives the same functionality but is 100 times better that that.

While Merb is merging into Rails. In Rails 3 we will be witnessing this remarkable feature of Merb in Rails as well. If the planning of new core team goes well...We will be able to mount any of our rails application in another very easily. Core team has given a tentative date for Rails 3 by next RailsConf in May. I can not wait to explore all these  good features. Just keeping my fingers crossed…


Merb + Rails == Great Software


So you heard the news??? Yes, Merb and Rails are going to merge in Rails 3 If thats true it will be a great merger o all times in ruby community. The largest framework of Ruby glued with the fastest one will be cool.

One of the thing which I loved in Merb is its agnostic feature. Specially ORM to quote. As I found Datamapper to be more efficient and useful then ActiveRecord in Rails. If we can use Datamapper in Rails it will be the coolest thing.

While trying Merb I also felt like most of the things are implemented in the same way as in Rails. So the basic difference is just in the values Merb advertise or rather built on …

* Being Agnostic

* Prefer Plugin

I am just waiting for Rails to adopt those values so it could be more efficient and more lovable :)


Ruby Funday: Live (Conclusion)


Sorry I am posting my last entry a bit late but by the time I finished, the wireless was not there. So here are the last few highlights of Ruby Funday.

Hmmmm… we had a good time at funday but after lunch and free T-shirts most of the people went away. :(

Anyways I was talking about Gogo’s session on “Air on Rails”. He created a flex application having backend in rails, little lesser than Yammer desktop app in about one hour. Wanna go into details… better if you read his own explanations .

Later on we had a session on Sphinx by Rishav where he compared the 2 sphinx based plugin; UltraSphinx and ThinkingSphinx. Sphinx is the fastest available full text search engine.

Conclusion took place with Akhil’s presentation on UltraSphinx…

Well not actual conclusion…

The fun day had a lot more fun to take place before conclusion. Which involved a ultimate music session by Sur and Hemu. A tremendous Jamming where every contributed…


Ruby Funday- The new beginning.


ruby funday First Barcamp now Ruby Fun Day. Seems like Delhi is becoming the hub of all the un-conference startups. After the huge success of BarcampDelhi, Delhites are now bringing Ruby Funday to India. Its the first Ruby and Rails Full Day event in India.

The Ruby/Rails lovers dream come true event is going to happen on 22nd of November 2008. So please mark the Saturday in your calender to go to Impetus Technologies at Noida, where the event is taking place.

Hoping for a day full of fun and learning as there are many Geeky speakers enrolling each day.


Issue with Rails 2.0.2 and Ruby 1.8.7


I had been setting up a test server yesterday for one of the app I am working on. Setting up Rimuhosting went smoothly and I was able to see this new baby online. I was happy and started testing. But just after 1-2 clicks i started getting the page. “We are sorry but something went wrong” …
:O :O :O
How did this happen???? it was working fine locally????
Well i know it happens so i checked the log. It said ActionView::TemplateError (undefined method `[]‘ for #<Enumerable… something like this.
But what is this error i couldn’t find. One more thing that i noticed was that it only happens when I am rendering something thorough ajax. This seems like error in Rails.But I was using freezed 2.0.2 version which is fine at local at both development and production mode. Yes right we are not developing on 2.1 as we are using active_scaffold and to avoid the infamous issue between the too we are still on 2.0.2.
So back to my point. I searched a lot but couldn’t find any thing which can help me. Somebody else has got the same issue and filed the ticket here. But noone else could reciprocate the error.
Then suddenly my luck hit and i got a search result in Spanish, which quote the same error i got. I took help of my best buddy Google again & ….Ahhhh ….. i feel so thankful to Blexter for posting this on his blog.
He said that Rails 2.0.2 is released before Ruby 1.8.7 which adds a method chars to class String:. Where Rails defined a method that return a ActiveSupport:: Multibyte: Chars, but if we run into a 1.8.7 we will interpret that to implement the method of a String chars, we return one enumerator so that there already can move around.
The solution he gives is easy either upgrade to 2.1 or remove the method from ruby String class by adding following code to any initializer (eg config / initializers / fixes.rb): or in enviornment.rb(For quick fix).
begin
String.class_eval { remove_method :chars }
rescue NameError
# all Ok
end

Simple na… :)

Strange behaviour of respond_to in IE


In recent days i have monitored a very strange behaviour of respond_to in IE.I am sharing my experience in hope that somebody might explain it to me. As i cudnt find anything related to this from my best teacher google :(

I am using edge rails in one of my projects. some where in that i have used respond_to in following way…


def show
respond_to |format| do
format.js {render :partial=>'show'}
format.html {}
end
end

When i checked the response in firefox for html and xml both requests type, it was perfect. But when i checked html response in IE 6 creates a blunder :O.It was returning a js file with the javascript response.

But when i changed the code and placed the html call first and then checked xml call it worked fine in IE too.

def show
respond_to |format| do
format.html {}
format.js {render :partial=>'show'}
end
end

Now can somebody tell me why is this happening and anyone else faced this issue ever?


Ruby/Rails Music album


Its melodious …its amazing and i can keep humming one or other track all the time. Really i loved it :)

Chris has the music for Ruby/Rails Community.He calls is IRB Mix .Tape and its just fantastic.

Track 4 about sandboxing is just mind blowing…

$ ruby script/console --sandbox
Loading development environment in sandbox.
Any modifications you make will be rolled back on exit.

And Track 5 about underscore operator (_) .I hadnt found yet anything in irb giving the value of last evaluated expression in Ruby. But ‘_’ does this cake thing for me. Good job Chris :D

One more small thing that i learned from one of the comment….

>> 4*4
=> 16
>> 4**4
=> 256
>> 100**100**100
c:/ruby/lib/ruby/1.8/rational.rb:543: warning: in a**b, b may be too big
=> Infinity
>>


Pdf-writer with login engine problem


If you are using pdf-writer with login engine, you can encounter a nasty problem with transactions in login engine like me(gosh… this was crazy). This is because login engine uses transaction-simple module (which is a part of transaction-simple by  Austin Ziegler but not the whole gem) included in rails 1.1 in active record.

While including pdf-writer it require the whole transaction-simple library.So in such a case the simple.rb file is required twice in the application.Which creates a problem in registration in login engine as it uses tranactions.

This ticket is discussed in here and a patch is also available…


http://dev.rubyonrails.org/ticket/4732


http://dev.rubyonrails.org/ticket/4932

Bad news is it can not be fixed before rails version 2 according to DHH ‘s response[:(]


Simple star rating in Rails


Those who wants to include simple 5 star rating mechanism in their ROR application.Can include a couple of functions in their helper to provide a form a rating field and display the result.Of course no 1/2 ratings can be achieved through this way. One needs to include the below given two function to some helper. And in view inside form tag call…


  star_rating_field("object", "fieldname", options)

Options are location, prefix, active_img, grey_img, hover_img…

For displaying the result of the rating in star images format…call from view


  img_tag_for_star_rating(rating_value,options)

Options are location, active_img, grey_img, hover_img…

Download the function to include in helper from here …I am finding it very difficult to put the code in wordpress without tampering so better to put it somewhere else ;)

Update: the file gets removed everytime.I m trying to out the code here only...


  #General function for star rating
  # Use these function as helpers
  # No half ratings are handled here
  # options can hav ...
  # location=>location of images( you need to have star_active.gif, star_grey.gif, star_hover.gif in this directory or provide names of image file in options)
  # prefix => prefix to append to each ids in DOM for descrimination of more then one star rating in the same page
  # grey_img => name of inactive/grey image of star
  # active_img => name of active image of star
  # hover_img => name of hover image of star
  def star_rating_field(obj_name, field_name, options={:location=>'/images',:hover_img=>"star_hover.gif", :active_img=>"star_active.gif", :grey_img=>"star_grey.gif"})

    # append a hidden field to store value of viz system field
    # this field is to be changed as hidden after testing
    hid = text_field(obj_name, field_name)
    hid_id = "#{obj_name}_#{field_name}"
    pref_id = options[:prefix].nil? ? 'star' : options[:prefix]+'_star'
    img_location = options[:location]
    # set initial value by javascript
    jscript = ""
    jscript += "var a; var v = parseInt($('#{hid_id}').value); for(var i = 1;i"
    img = ''

    # add images to field
    for i in 1..5
      img += ""+' '
    end
      return  img + hid + jscript
  end

  def jscript_for_star_rating(pref_id, img_location)
    jscript = " function set_star_status(n, id)    {  if( $(id).value != n){ for(var j=1; j"star_active.gif", :grey_img=>"star_grey.gif"})
    image = ''
    for i in 1..5
      if i "
      else
        image += ""
      end
    end
    return image
  end

Note:Do remember to include prototype library from script.aculo.us in your page.

UPDATE2:phew…finally trying to add the file again.Hope it work fine this time :( try this=>Star Rating functions


Follow

Get every new post delivered to your Inbox.