Archive for September 2009

h1

10 Things you want to know if you start with heroku.com

September 15, 2009

1. start with reading how to use git (http://en.wikipedia.org/wiki/Git_%28software%29)

2. create your local git repository (git init)

3. get a free heroku.com account

4. install the heroku gem (gem install heroku)

5. add your files (git add .)

6. commit your files (git commit -m „my new app“)

7. create your app @ heroku (heroku create) –> public key needed!

8. push your app to heroku (git push heroku master)

9. check the output (heroku logs)

10. add needed gems (create a .gems file in your folder and add it to the repository, each gem a new line e.g. hpricot)

11. get more Infos @ heroku (http://docs.heroku.com/)

h1

ActiveRecord::Errors.new(self) and undefined method self_and_descendants_from_active_record

September 9, 2009

We recently switched to rails 2.3.4 and noticed the following error:

undefined method self_and_descendants_from_active_record for Cart:Class

Our Cart class has no ActiveRecord binding, but we need some validations, so we simple use

@errors = ActiveRecord::Errors.new(self)

and overerride the valid? action.

But now we get the undefined method error.

Solution

Implement in your class also:

 def self.self_and_descendants_from_active_record
    [self]
  end

  def self.human_name(options = {})
    defaults = self_and_descendants_from_active_record.map do |klass|
      :"#{klass.name.underscore}"
    end
    defaults < [:activerecord, :models], :count => 1, :default => defaults}.merge(options))
  end

  def self.human_attribute_name(attribute_key_name, options = {})
    defaults = self_and_descendants_from_active_record.map do |klass|
      :"#{klass.name.underscore}.#{attribute_key_name}"
    end
    defaults << options[:default] if options[:default]
    defaults.flatten!
    defaults < defaults, :scope => [:activerecord, :attributes]))
  end

and you can still use ActiveModel like validations 🙂

h1

javascript value and rails I18n

September 8, 2009

Today i stumble about the following problem, i have a javascript value and want it inside a localized rails string.

„This is my string javascriptvalue and so on …“

solution

'<%= T("This is my string ## and so on ...", :translate_string) %>'.sub(/##/, javascript_value);

i simple use javascript sub to replace ## with the javascript_value.

🙂