Valentin V
Valentin V

Reputation: 25729

Is there a way to run a view inside a partial

I know this is odd. but I can't figure other ways to do what I need. I have a controller: report and a view: report. Also I have a view that acts as a dashboard where I can see several zones (partials). I need to add this report view to my dashboard but don't know how. This report view utilizes complex logic from controller and displays the results. How could I "stuck" the (logic+presentation) of exising view (report) into my partial, so I could use it on my dashboard??

Thank you. Valve.

Upvotes: 1

Views: 156

Answers (4)

spas
spas

Reputation: 1934

I would suggest to refactor the code from the report controller (if this is the one that contains the "complex" logic) and put it into a wrapper class that can be used by the dashboard and report view.

Upvotes: 0

ucron
ucron

Reputation: 2852

If I'm not mistaken you can do a render_component, but this is completely frowned upon nowadays.

This is the easiest way to your problem though

Upvotes: 0

Mike Woodhouse
Mike Woodhouse

Reputation: 52316

(I hope I'm understanding the problem, here...)

This part seemed significant:

This report view utilizes complex logic from controller

As a general rule, controllers should be simple. Really simple. The rule of thumb is "thin controller, fat model" (Rails Envy made some entertaining but useful screencasts on the subject)

What would happen if you created a new model (quite possibly not inheriting from ActiveRecord::Base) that encapsulated the logic you want to deliver into the partial? Then different controller/action combinations can deliver the information into your views as necessary/required.

Or have I completely missed the point (not impossible!)

Upvotes: 1

Reputation:

I had a similar problem a while ago, when they deprecated render_controller. The only solution I found then was to use ajax, passing a parameter to the page you want to load that bypasses the layout.

Upvotes: 0

Related Questions