Any way to pass state to a component?

I am trying set up a rails app that utilizes components. I need to be
able to pass some state (a bunch of name value pairs) from the Main
controller to the component.

Is there any way to pass this state info using render_component?

Regards

I am trying set up a rails app that utilizes components. I need to be
able to pass some state (a bunch of name value pairs) from the Main
controller to the component.

Is there any way to pass this state info using render_component?

Before you venture down the road of components, you might heed this
disclaimer added to the documentation for components in Edge Rails:

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.

David Heinemeier H.
http://www.loudthinking.com – Broadcasting Brain
http://www.basecamphq.com – Online project management
http://www.backpackit.com – Personal information manager
http://www.rubyonrails.com – Web-application framework

What are your thoughts on including ViewHelpers/ActionControllers in
plugins
versus components? When the need arises to do this, is that the time to
make the switch from plugin to engine?

On the off chance you are okay with plugins including ActionControllers,
is
there a “safe” way to use named routes in the plugin init.rb to prevent
naming conflicts with apps that make use of the plugin? For example I
add a
named route for FooController, with the name “stevelongdo_foo”, more
than
likely I will not be causing a naming conflict with an existing app,
unless
someone else has my domain name…

There is. I’m using render_component_as_string to call the component
from within another controller, and I pass through the parameters there.
My line of source for this looks like this.

@section_content = render_component_as_string(:controller =>
component_controller, :action => action, :params =>
current_component_params)

Please feel free to drop me a line if you’d like to see more of this
source code or talk about this further. I’m not 100% happy with my
approach, and I’d like to hear more ideas. :slight_smile:

regards,

Craig

Hello,

Still farily new to RoR and I’m running into a routing problem.

I am making an a multi-store ecommerce solution to replace one that I
created a few years ago in ColdFusion, and I’m currently working on
the administration site for it. What needs to happen is that a user
first selects which store they want to administer, and then within
that they can manage products, orders, etc. I really like/need to
replicate the style of routing that basecamp employs for its projects
(since its basically the same sort of deal).

Right now, I have:

map.store ‘store/:storeid’, :controller => ‘stores/main’, :action =>
‘setStoreSession’

This works fine. It takes in the storeid, then sets that id into a
session variable and shows the user the main index page for that
particular store. What I am not clear on is how to best continue
this for other controllers and actions within that store.

What I want is to end up with something that will look like

localhost/store/54/products
localhost/store/54/orders/detail/834
etc

Any help on how to achieve that, and how to be able to automatically
extract the session id into the appropriate place (rather not
manually specify this every time…maybe a helper would be best for
this? any way i could subclass the named mapping, so that store_url
always set the id if it was present in the session?).

Thanks,
Dave