Giter Site home page Giter Site logo

rails / render_component Goto Github PK

View Code? Open in Web Editor NEW
38.0 5.0 52.0 82 KB

NOTICE: official repository moved to https://github.com/malev/render_component. Components allow you to call other actions for their rendered response while executing another action

Home Page: http://rubyonrails.com/

Ruby 100.00%

render_component's Introduction

Components allow you to call other actions for their rendered response while executing another action. You can either delegate
the entire response rendering or you can mix a partial response in with your other content.

  class WeblogController < ActionController::Base
    # Performs a method and then lets hello_world output its render
    def delegate_action
      do_other_stuff_before_hello_world
      render_component :controller => "greeter",  :action => "hello_world", :params => { :person => "david" }
    end
  end

  class GreeterController < ActionController::Base
    def hello_world
      render :text => "#{params[:person]} says, Hello World!"
    end
  end

The same can be done in a view to do a partial rendering:

  Let's see a greeting:
  <%= render_component :controller => "greeter", :action => "hello_world" %>

It is also possible to specify the controller as a class constant, bypassing the inflector
code to compute the controller class at runtime:

<%= render_component :controller => GreeterController, :action => "hello_world" %>

== When to use components

Components should be used with care. They're significantly slower than simply splitting reusable parts into partials and
conceptually more complicated. Don't use components as a way of separating concerns inside a single application. Instead,
reserve components to those rare cases where you truly have reusable view and controller elements that can be employed
across many applications at once.

So to repeat: Components are a special-purpose approach that can often be replaced with better use of partials and filters.

Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license

render_component's People

Contributors

dpowell avatar lifo 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

render_component's Issues

fails for rails 2.3.5

With rails 2.3.5 this plugin fails with
/var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/module/aliasing.rb:33:in alias_method': undefined methodset_session_options' for class `ActionController::Base' (NameError)

There are blogs verifying the problem here:
http://dothingssimple.wordpress.com/2009/08/07/hello-world/
http://www.42.mach7x.com/2009/06/24/undefined-method-render_component-with-activescaffold-and-rails-2-3-2/

But the solution is use another (now deleted github repository)

Problem with sweepers

Hi,

I discovered this error with ActiveScaffold:
If you have sweepers activated, you will get a NoMethodError, because Sweepers after action is called twice.
First time, it sets self.controller = nil, so second time it fails to get controller_name.

This behaviour is mentioned in http://dev.rubyonrails.org/ticket/6199, but since components were removed from rails it was never fixed there...

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.