Site Archives

Deprecated Finders in Rails 1.1.5


These Finders are deprecated

find_first [use find(:first)]
find_all [use find(:all)]
find_on_conditions [use find(:conditions)]

Ajax pagination links: Create pagination links with link_to_remote


Here is a method by mixonix to create pagination links by link_to_remote. Copy this code in your helpers/application_helper.rb
def ajax_pagination_links(paginator, options={})
options.merge!(ActionView::Helpers::PaginationHelper::DEFAULT_OPTIONS) {|key, old, new| old}
window_pages = paginator.current.window(options[:window_size]).pages
return if window_pages.length { options[:name] => first }.update(options[:params] ))
html 1
html page }.update(options[:params] ))
end
html { options[:name] => last }.update( options[:params]))
end
end
end
and use following code for creating [...]

Tab Problem in rails .rhtml files


The situation was: running Ruby 1.8.4, Rails 1.1.2, on WinXP & WEBrick server.
My application was working fine, but as I installed Rmagick my application crashed.
I got strange errors like:
compile error /script/../config/../app/views/layouts/application.rhtml:18: parse error, unexpected $, expecting kEND
if I refresh again the error actually changes(further refreshes flip back & forth between errors):
compile error
/script/../config/../app/views/layouts/application.rhtml:18: Invalid char `01′ [...]

converting all newline characters to br tag


I was surprised as there is no function in ruby to convert all newline characters to <br>.
Here is a php nl2br equivalent method to convert all newline characters (\n) to break tag (<br>) in a string.
def nl2br(s)
s.gsub(/\\n/, ‘<br>’)
end