5

What I want to do is have 2 different controllers, client and test_client. The client controller is already built and I want to create a test_client controller that i can use to play around with the UI of the client and adjust it as needed. I am mainly trying to get around the validation i have built into the client and its dependence on an admin controller that loads the data.

so i want the test_client controller to load a sample data set and then render the client controller's index view so i can adjust the clients UI. That is all.

I tried this in the test_clients index method:

class TestClient
    def index
        render :template => 'client/index'
    end
end

but i get an error because it cannot find the client partials as it is looking in the current controllers view for them...

So I have looked into this already and most people say that you should never make such a call but i think that this case is a reasonable usage...I just need to figure out how to get it to work.

2
  • Are you using git? Because this is a nice use-case for git branches IMHO. Commented Dec 1, 2011 at 18:00
  • I am actually using svn but that is a good idea. I might try that on my next project. Commented Dec 2, 2011 at 18:38

3 Answers 3

6

You will need to adjust your view so that the path to the partial you need is in the form 'controller/partial'. In this case probably 'client/partial'. Then you can simply use render 'client/index' as before.

So say somewhere in your view you have this:

<%= render :partial => 'info' %>

You will want to change it to this:

<%= render :partial => 'client/info' %>
Sign up to request clarification or add additional context in comments.

2 Comments

this solution worked fine even though I am not a huge fan of having the controller hard coded in there its not going to effect anything for me unless i rename the controller.
If this is a partial used in multiple controllers, I usually put them under app/views/shared, then you do render :partial => 'shared/info' or something similar. Might want to name it better then.
2

Convert your client controller views to partials, create empty views for all actions in test_client controller, render client partials for respective test_client views.

Example:
client view
index.html.erb to _index.html.erb

test_client view
index.html.erb
in this view, <%=render :partial => 'clients/index', :locals =>{ }%>

Comments

0

You could do this in a number of ways and everyone is different. One way you could do it, is by putting your finders into a presenter. Then turn some data in the index view into a partial or you can render the template with layout set to false.

Then in the client_test view you can render that index with the presenter associated with it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.