Ruby on Rails controller and architecture with cells

684 Views Asked by At

I decided to try to use the cells plugin from rails:

http://cells.rubyforge.org/community.html

given that I'm new to Ruby and very used to thinking in terms of components. Since I'm developing the app piecemeal and then putting it together piece by piece, it makes sense to think in terms of components.

So, I've been able to get cells working properly inside a single view, which calls a partial. Now, what I would like to be able to do (however, maybe my instincts need to be redirected to be more "Rails-y"), is call a single cell controller and use the parameters to render one output vs. another.

Basically, if there were a controller like:

def index
   params[:responsetype]
end

def processListResponse
end

def processSearchResponse
end

And I have two different controller methods that I want to respond to based on the params response type, where I have a single template on the front end and want the inner "component" to render differently depending on what type of request is made. That allows me to reuse the same front-end code.

I suppose I could do this with an ajax call instead and just have it rerender the component on the front end, but it would be nice to have the option to do it either way and to understand how to architect Rails a bit better in the process.

It seems like there should be a "render" option from within the cells framework to render to a certain controller or view, but it's not working like I expect and I don't know if I'm even in the ballpark.

Thanks!

1

There are 1 best solutions below

0
On

How would the cell know in which controller it is rendered? This would break encapsulation.

You can use #render_cell in your controller view and maybe put some decider around it? Is that what you're asking for?