Topic: Components

Would it be proper to have a Components controller, specifically dedicated for various components that your application might require? Or would this violate some sort of rails programming ethics?

Re: Components

Since components don't have any way to accept user input, I think this is perfectly acceptable. Without knowing the details of the application it's hard to determine if there's a better way though.

Railscasts - Free Ruby on Rails Screencasts

Re: Components

I'm currently working on the administrative backend for one of my rails sites, and I have a sidebar that displays help information as well as a subnavigation menu. Both of these "components" will be used frequently across ~15 different views.

Also another quick question, i want to pass the current controller and action to a component, I'm  currently using:

<%= render_component(:controller => "admin/components", :action => "help", :params => { "controller" => @params[:controller], "action" => @params[:action] }) %>

But in the component action I'm getting the controller/action for that component. Is there another way of doing this without first copying the current controller/action to variables, and passing those?

Thanks,

Gianni

Last edited by gianni (2007-02-03 01:51:15)

Re: Components

Try giving the passed parameters a different name:

<%= render_component(:controller => "admin/components", :action => "help", :params => { :from_controller => params[:controller], :from_action => params[:action] }) %>

You should then be able to access them in the component through params[:from_controller]/params[:from_action]. IIRC that's what I did to solve this problem when I used to use components. It's been a while since I've used them though.

Railscasts - Free Ruby on Rails Screencasts

Re: Components

Thanks, worked perfectly! When you say you don't use components anymore is that because you now use something better, or you just haven't had the need for them lately?

Gianni

Re: Components

A little bit of both. I'm finding a combination of helpers and partials can do what i used to do with components. I know components are still useful in some cases, but I haven't come across this yet.

See this post and the following replies for a discussion on this.

Railscasts - Free Ruby on Rails Screencasts