15
Jun

Rails 2.3 has a good solution for multi model forms. But there is not much examples of  how to use accepts_nested_attributes_for with has_one relation.

Assume that we have a Book model which has one Author.



Controller :

View:


No special action is needed for create method of BooksController,  attr_accessible is not necessary for Book model. Just don’t forget to add the second parameter (@book) of form_for and build your nested object (@book.build_author).

21
Jan

If you have trouble when converting string to array, check if your string includes any line feed (\n). Check how Array("string") behaves:

irb(main):001:0> Array("izzet emre \nkutlu")
=> ["izzet emre \n", "kutlu"]

This output is not what most of the people expected. Be careful!

26
Dec

A simple plugin which displays Working With Rails recommendation badge.

  1. Download the plugin.
  2. Extract the plugin to your wordpress plugin directory.
  3. Activate the plugin.
  4. Add the widget to your sidebar.
  5. Enter your information.

It’s version is 0.1 so comments will be appreciated.

14
Dec

If you have recently updated to Rails 2.2.2, you may encounter this error when you want to start your application:

/.gem/ruby/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:445:in
`load_missing_constant': uninitialized constant Inflector (NameError)

As I learned from Paul’s post usage of Inflector class is changed a bit. You can see the difference when you compare the inflections.rb files. Path of the file is yourApp/config/initializers/inflections.rb

inflections.rb (Rails 2.1.0)

 Inflector.inflections do |inflect|
  .
  .
  .
 end

inflections.rb (Rails 2.2.2)

 ActiveSupport::Inflector.inflections do |inflect|
  .
  .
  .
 end

In my situation changing Inflector to ActiveSupport::Inflector was enough to solve the problem.

27
Aug

This is what happened when I want to install rmagick gem.

username@username-desktop:~$ sudo gem install rmagick
Bulk updating Gem source index for: http://gems.rubyforge.org/
ERROR:  could not find rmagick locally or in a repository

What the hell…
After some googling I found that RubGems 1.1.x is buggy and and update to RubyGems 1.2 is necessary.
To learn your RubyGems version:

username@username-desktop:~$ gem -v
1.1.0

Read the rest of this entry »