Giter Site home page Giter Site logo

rails-parts's Introduction

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

rails-parts's People

Contributors

drogus avatar hubertlepicki avatar lukaszx0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rails-parts's Issues

View path is not properly set on Rails 3.0.0 application

Hi,

Little problem and quic'n'dirty workaround:

Background: Fresh Rails 3.0 application, HAML, rails-parts from master installed as plugin.
Part was successfully generated, however while rendering part, "Missing template.." error is thrown.
After looking around, I found out that Parts::Base.view_paths is empty.

Quick workaround is to create initializer with following code:
Parts::Base.append_view_path "app/parts/views"

url_for not available in Parts

Hi,

I am just wondering, is it intentional that url_for (and thus most of paths) is not available in Parts?

I mean -- is it by design, so that it doesn't include too much from ActionController::Base, or it's just not done?
Best,
H.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.