Archive

Archive for the ‘rails’ Category

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

December 31, 2008 Ritu Leave a comment

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

December 26, 2008 Ritu Leave a comment

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 :)

Categories: Ruby on Rails, merb, rails Tags: , ,

Ruby Funday: Live – Part 2

November 22, 2008 Ritu Leave a comment

Sur’s PURE CODE PRESENTATION went very well. Had a lot of discussion on Ruby not needing the Type Casting which leads to a lil bit doubt coming up in JAVA guys interested in Ruby.

Afterwards we had a real good session by Aditya from Impetus. Aditya talked about the new product they are gonna launch very soon. Its a deployment tool written in C+Ruby Combo. The good news about it is its Open Source which increases its scope widely for future.

In his talks Aditya point out some main features of his deployment product. Which he is calling “ATLAS” right now and is in pre alpha version. Some main aspects they have focussed upon while developing are as follows:

  • Runs Rails and Rack compliant applications.
  • Multiple web application support.
  • Intelligent load balancer.
  • and many more to list…

The presentation that followed Aditya’s was Sid from Vinsol. He presented on Internationalization in Rails 2.0. Which was pretty state forward and funny when you see the English got converted in Hindi statements. He compared the Internationalization in Rails prior to 2.2 with Gibberish plugin and the new Rails i18gem implementation. The i18 implementation makes it pretty simple to implement. It has the built-in Active Record error message internationalization suport which was missing in previous release of Gibberish. So thats another cool feature of Rails 2.2

Talking about Rails 2.2. Its officially out just few hours back. Check out http://explore.twitter.com/d2h/status/1017059364.

I am back after Lunch now. And Gaurav is Presenting on ‘Air on Rails’. Check out next post for that.

I ‘ll be back again. :)

Now steriods in Plugins…

July 27, 2007 Ritu 3 comments

Wow cool idea ;) … And the plugin i am talking bout seems promising too. The plugin of the day for me is acts_as_taggable_on_steroids. The writer says it enhances acts_as_taggable by DHH with features like Caching and tagcloud calcultions. Although i could not use it till now, but i m planning to check it out in my new project as soon as the first phase completes which seems to be very near :D

Categories: plugins, rails

Strange behaviour of respond_to in IE

December 10, 2006 Ritu 4 comments

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?

Categories: General, Ruby on Rails, rails

Ruby/Rails Music album

November 2, 2006 Ritu 1 comment

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
>>

Categories: Ruby on Rails, rails, ruby

Pdf-writer with login engine problem

August 27, 2006 Ritu 2 comments

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[:(]

Categories: Ruby on Rails, rails

Simple star rating in Rails

August 14, 2006 Ritu 19 comments

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

Automatic Ajaxification With KRJS

July 25, 2006 Ritu 3 comments

KRJS plugin developed by Chew Choon Keat could be called an extension to RJS templates by Cody Fauser . In his post KRJS: RJS without messing the Views Keat explains how KRJS can be used to update functionality in views without even touching the views.

Some Interesting Dynamic Finders

July 13, 2006 Ritu 1 comment

find_or_create_by_X: As obvious by name this dynamic finder method allows you to find or create a new record on the basis of attributes passed. A very good example by DHH himself goes like this…

class Account < ActiveRecord::Base
has_many :people do
def find_or_create_by_name(name)
first_name, *last_name = name.split
last_name = last_name.join " "
find_or_create_by_first_name_and_last_name(first_name, last_name)
end
end
end


person = Account.find(:first).people.find_or_create_by_name("David
Heinemeier Hansson")
person.first_name # => "David"
person.last_name # => "Heinemeier Hansson"

find_or_initialize_by_X : This new method in available in edge rails now. Its almost similar to the find_or_create_by_X finder. The basic difference is that this method unlike find_or_create_by_X only initialize the object and do not saves it.

Categories: rails