Notes posted by avakhov

RSS feed
April 16, 2010
5 thanks

Require file from the same folder

If you want to require file from the same folder, the simplest way is

require File.expand_path('../file-to-require', __FILE__)

If your file is /lib/book.rb

File.expand_path('../page', '/lib/book.rb') => '/lib/page.rb'
January 20, 2010
3 thanks
August 18, 2009
0 thanks

Using custom object via :object

Sometimes you need use select not only with @object as by default. For example if you have helper method like :

def select_parent_for(page)
  select(:page, :parent_id, Page.all.collect{|p| [p.name, p.id]} ) # <--- mistake!

In selected line you will use @page instead parameter of method page.

The options has parameter :object (and all form helpers has such parameter)


def select_parent_for(page)
  select(:page, :parent_id, ..., :object => page)
August 16, 2009
1 thank

Small notice about recognize urls with specific HTTP verbs

This is wrong ruby syntax:

assert_recognizes {:controller => 'items', :action => 'create'}, {:path => 'items', :method => :post}

Parentheses are obligatory in this case:

assert_recognizes({:controller => 'items', :action => 'create'}, {:path => 'items', :method => :post})
August 15, 2009
0 thanks

To find element ant not to find element

If you want to see administration panel:

assert_select "div.admin-panel"

But if you want to NOT see administration panel just write:

assert_no_tag 'div', :attributes => {:class => 'admin-panel'}