Archive for August, 2006
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)]
Add comment August 23, 2006
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 <= 1 unless
options[:link_to_current_page]
first, last = paginator.first, paginator.last
returning html = '' do
if options[:always_show_anchors] and not window_pages[0].first?
html << link_to_remote(first.number, :update => options[:update], :url => { options[:name] => first }.update(options[:params] ))
html << ' ... ' if window_pages[0].number - first.number > 1
html << ' '
end
window_pages.each do |page|
if paginator.current == page && !options[:link_to_current_page]
html << page.number.to_s
else
html << link_to_remote(page.number, :update => options[:update], :url => { options[:name] => page }.update(options[:params] ))
end
html << ' '
end
if options[:always_show_anchors] && !window_pages.last.last?
html << ' ... ' if last.number - window_pages[-1].number > 1
html << link_to_remote(paginator.last.number, :update => options[:update], :url => { options[:name] => last }.update( options[:params]))
end
end
end
and use following code for creating links
<%= ajax_pagination_links @pages, {:params => {:search_query => @params[:search_query]} } %>
7 comments August 16, 2006
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′ in expression
./script/../config/../app/views/layouts/application.rhtml:19: parse error, unexpected tCONSTANT, expecting kEND
./script/../config/../app/views/layouts/application.rhtml:20: parse error, unexpected tCONSTANT, expecting kEND
./script/../config/../app/views/layouts/application.rhtml:21: Invalid char `06′ in expression
./script/../config/../app/views/layouts/application.rhtml:21: parse error, unexpected $, expecting kEND
Then my colleagues told me the root of this problem, this was because of tabs in .rhtml files. Also they told me the simple solution:
Put template = template.gsub(/\t/, ” “) in your
\vendor\rails\actionpack\lib\action_view\base.rb file at line 496 as very first line of def compile_template
Restart webserver and you are done….
6 comments August 10, 2006
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
12 comments August 7, 2006






