Merb parts ported to rails.
As it's initial and a bit experimental implementation please note that API can change (currently it's copied from Merb)
Just add such line to Gemfile:
gem "rails-parts", :require => "parts"
Generate part class using rails generator:
rails generate part Articles index
Add some logic to index method of your part:
# app/parts/articles_part.rb class ArticlesPart < Parts::Base def index @articles = Article.limit(10) end end
and to the view file linked to the part
# app/parts/views/articles_part/index.html.erb Articles: <%= @article.map(&:title).join(", ") %>
Now you can render it in the view of any controller with:
<%= part ArticlesPart => :index %>
You can also attach params that will be available in Part as params hash:
part ArticlesPart => :index, :limit => 5 # app/parts/articles_part.rb class ArticlesPart < Parts::Base def index @articles = Article.limit(params[:limit] || 10) end end