Zero width ExtJS HTMLEditor on IE7
Do you have a zero width HTMLEditor on IE7 only?
Don't waste hours like I did trying to figure it out.
Pass in a 'width' argument to the HTMLEditor constructor. That did it for me.
Using ExtJS 3.2.1.
Will_paginate and AJAX
I have been using will_paginate ever since I started on Rails.
It's a great plugin for classic page rendering, but what if you want to use it with AJAX, so it updates a document element (a floating window layer, for instance) with the results instead of reloading the page?
Well, inspired on Redline's blog post (which almost worked for the latest version of the will_paginate plugin), I have the solution.
Create a link renderer. I put in under lib/remote_link_renderer.rb so Rails always loads it on startup.
class RemoteLinkRenderer < WillPaginate::LinkRenderer
def page_link_or_span(page, span_class = 'current', text = nil)
text ||= page.to_s
if page and page != current_page
@template.link_to_remote(text, {:url => url_for(page), :method => :get}.merge(@remote))
else
@template.content_tag :span, text, :class => span_class
end
end
end
On the view, when you are rendering the pager, do it like this:
<%= will_paginate @collection, :renderer => 'RemoteLinkRenderer' , :remote => {:with => ’value’, :update => ‘some_div’} %>
That's it!
How to paginate outside of the database with will_paginate
will_paginate is a great plugin. I have been using it since I started on Rails.
If you want to paginate records that are inside your database it works great.
But what if you want to paginate records that come from, say an external webservice?
Well, you can use the WillPaginate::Collection class.
This class will let you mimic the collection that will work on a pager, so you can use the view helper pager seamlessly throughout your app.
Just use it like this:
@entries = WillPaginate::Collection.create(1, 10) do |pager|
result = Webservice.get(...) # get your results
# inject the result array into the paginated collection:
pager.replace(result)
unless pager.total_entries
# the pager didn't manage to guess the total count, do it manually
pager.total_entries = result.count
end
end
New year resolutions
Happy new year to everyone!
I haven't posted for a while - had a busy end-of-year...
Things I want to look into early 2010:
- Haml
- Rails 3
- Node.js
- Erlang
- Hadoop
- Scala
- EJB 3
- Ruby alteranative VMs (JRuby, MacRuby, LevMag)
- ...and more cool blog posts!
Tools for the job
Here are some tools / gems / plugins I can't live without:
IDEs:
- Aptana Rad Rails - very good at Rails and Ruby. It's based on Eclipse - Java - so it tends to bloat
- gedit- Tiny footprint, simple. Great for web and PHP with the right plugins and conf tweaks
Ruby / Rails plugins:
sweepy – Distributed and scalable file caching expiration in Rails
Followin up on my post about Rails cache on a distributed environment, I recently published a Rails plugin called sweepy.
Sweepy allows you to expire file-based cache (page cache and fragment cache) on Rails on multiple boxes.
If you don’t want or don’t need to setup memcached, and just want to simply use Rails page and / or fragment caching, sweepy automatically handles page expiration.
You can use the Rails expire_page and expire_cache API, no need to change existing code.
How to alias_method_chain a class method on Rails
Sometimes, when building a plugin, you have to extend Rails behaviour using alias_method_chain.
So you do, on the included module:
...
def self.included(base)
base.send :include InstanceMethods
base.class_eval do
alias_method_chain :method_i_want_to_extend, :my_feature
end
end
module InstanceMethods
def method_i_want_to_extend_with_my_feature(args)
(do something or not...)
method_i_want_to_extend_without_my_feature(args)
(do something or not...)
end
end
...
What if the method you are extending is a class method?
Tutorial – advanced styled_objects on Rails
Following the building and styling a Rails app with styled_objects tutorial, we will learn how to use some advanced features of styled_objects and also some best practices to keep your CSS code maintainable while using styled_objects.
Tutorial: building and styling a Rails app with styled_objects
How to keep your stylesheets clean and organized using Rails
This tutorial covers building a web application from scratch using Rails with the styled_objects plugin.
styled_objects Rails plugin
Yesterday I released the styled_objects Rails plugin.
styled_objects is a Rails plugin for simplifying stylesheet management on your application.