0.01
No commit activity in last 3 years
No release in over 3 years
This gem allows you to use parts in your rails app
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

~> 3.0.0
 Project Readme

Rails Parts¶ ↑

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)

Install¶ ↑

Just add such line to Gemfile:

gem "rails-parts", :require => "parts"

and run:

bundle install

Usage¶ ↑

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