inside_layout Broken in Rails 2.1

My good old friend for nested layouts, inside_layout

def inside_layout(layout, &block)
  layout = layout.include?('/') ? layout : "layouts/#{layout}"
  concat(@template.render_file(layout, true,
    '@content_for_layout' => capture(&block)), block.binding)
end

suddenly stopped to work, and since i am so grateful for his long months of service, he got replaced by the next best thing ๐Ÿ˜‰

<% @content_for_layout = capture do %>
...some text or html...
<%= render :file=>'layouts/application', :content_for_layout => @content_for_layout %>
ย 

Simple Tag IO with acts_as_taggable_on_steroids

Update: deleted since it is now redundant

Update: switch to acts_as_taggable_on_steroids more features, less pain/bugs ๐Ÿ™‚
Need simple input/output for tags and got acts_as_taggable_on_steroids ?

…..

and in your forms:

f.text_area('tag_list')

Done!

#Spec:
  it "does not create duplicated tags" do
    @taggable.tag_list = "Bad, Bad, Evil"
    @taggable.save!
    @taggable.tags.size.should == 2
  end

#Often need count of Tags ?
#taggings.rb
belongs_to :tag, :counter_cache=>'taggings_count'

Getting started with acts_as_searchable on Ubuntu

UPDATE

acts_as_searchable is no longer maintained, please switch over to the new and healthy world of search_do bug-free, clear structure and paginating!

Too many crappy tutorials around, with wrong or only partial information of how to get started. Took me almost 2 hours to get it working, so here comes a short How To/Summary for future reference.

  1. sudo apt-get install hyperestraier
  2. sudo nano /etc/default/hyperestraier (change NO_START from 1 to 0) -> autostart on boot
  3. sudo /etc/init.d/hyperestraier start
  4. http://localhost:1978/ -> admin/admin -> create new nodes (xx_test/xx_development/xx_production)
  5. script/plugin install http://github.com/grosser/search_do
  6. add to database.yml (once for every environment):
    estraier:
      host: localhost
      user: admin
      password: admin
      port: 1978
      node: xx_development
  7. >ModelName<.rb: acts_as_searchable :searchable_fields=>[:descr,:title] details
  8. Add all current models to the fulltext search:
    script/console
    >ModelName<.reindex!
  9. Check back in the corresponding node @ http://localhost:1978/ to see if documents have been created
  10. play around with >ModelName<.fulltext_search

Hope this helps ๐Ÿ™‚

more detailed help

Unobtrusive Autocomplete Rails Plugin

Auto complete solution, with customizable results (return just the word or word+id…) and no framework dependency, just use a plain text_field + class=> autocomplete and every autocomplete libary you like (included: jQuery).

autocomplete

# Controller
class UserController < ApplicationController
  autocomplete_for :user, :name
end

#Customized....
autocomplete_for :user, :name do |items,method|
  render :text => items.map{|item| "#{item.send(method)} -- #{item.id}"}.join("\n")
end

# View
<%= f.text_field :auto_user_name, :class => 'autocomplete', 'autocomplete_url'=>autocomplete_for_user_name_users_path %>

# Routes
map.resources :users, :collection => { :autocomplete_for_user_name => :get}

#JS
#any library you like
#(includes examples for jquery jquery.js + jquery.autocomplete.js + jquery.autocomplete.css )
jQuery(function($){//on document ready
  //autocomplete
  $('input.autocomplete').each(function(){
    var input = $(this);
    input.autocomplete(input.attr('autocomplete_url'));
  });
});

#Model(input/output association)
class User
  find_by_autocomplete('name')
end
class Post
  autocomplete_for('user','name') # auto_user_name= + auto_user_name
end
.

Not as thought free as the default version, but gives you a lot more control.

script/plugin install git://github.com/grosser/simple_auto_complete.git
README

RSpec response.should Information Enhancers

In case of failure the normal should be_redirect and its friends are far from helpful…

expected redirect? to return true, got false

expected "new", got nil

Now you can have this:

Status should be redirect but was 200(success)
 - rendered addresses/new
 - Flash:
    :error = Address contains errors!
 - Errors:Errors on @address(Address):
     City can't be blank

Usage

  • response.should redirect_to / render_template as normal
  • response.should have_been_success (i do not want to overwrite be_success…)
  • have_been_error
  • have_been_missing
  • have_been_redirect

Install

script/plugin install git://github.com/grosser/rspec_response_enhancer.git

add to spec/spec_helper.rb:
Spec::Runner.configure do |config|
  ...
  config.include(RspecResponseEnhancer)
  ...
end

And as added benefit you no longer need to build should be_success when you already have a should render_template, since render_template now gives detailed error messages!