# Rails - Any way to pass state to a component?

**URL:** <https://www.ruby-forum.com/t/rails-any-way-to-pass-state-to-a-component/72937>\
**Category:** Ruby\
**Created:** [February 24, 2006, 6:09pm UTC](https://www.ruby-forum.com/t/rails-any-way-to-pass-state-to-a-component/72937 "2006-02-24T18:09:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 24, 2006, 6:09pm UTC](https://www.ruby-forum.com/t/rails-any-way-to-pass-state-to-a-component/72937/1 "2006-02-24T18:09:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 24, 2006, 7:11pm UTC](https://www.ruby-forum.com/t/rails-any-way-to-pass-state-to-a-component/72937/2 "2006-02-24T19:11:00Z")

</div>

Check the docs, but I believe you can pass a hash called :params with  
any name-value pairs you need. They then show up in the @params  
instance variable in the components controller:

render\_component :controller =\> “foo”, :action =\> “bar”, :params =\> {  
:baz =\> “bil” }  
…  
class FooController  
…  
def bar  
@baz = @params[:baz] # “bil”  
…  
end

HTH.
