I've been looking for an easy way to render views (or templates). I've only seen complicated solutions all over the internet that involve getting the rendering engine, passing the context, which is normally an action view instance initialized with the original view paths, which are fetched from ActionController::Base, and then I can finally pass the local variables, this of course, if I am not using any instance variables inside the templates or I'm not using helper methods, for which I have to insert/include everything by hand, and then I still have some problems regarding relative location of partials, which are not infered outside the rails context.. uhf... Isn't there a main object I can call a simple #render method from?
Asked
Active
Viewed 236 times
3
-
Why are you trying to do this from the console? Seems like a weird use case. You may be better off using something like Liquid http://liquidmarkup.org/ – ADAM Aug 26 '13 at 09:26
-
I guess you can have a ruby file that does all those complicated things and include only that ruby file when you run your console. What exactly are you trying to achieve? If you want to debug your template then put a debugger in your template… – j03w Aug 26 '13 at 09:28
-
I'm sick of writing the templates by hand for my jasmine specs. I also don't want to make my rspec or cucumber scripts render stuff for my jasmine specs to test (too much dependency). So, I'm pre-rendering the necessary partials/templates before I actually start the jasmine:ci task. – ChuckE Aug 26 '13 at 11:16
-
@ADAM, I'm neither looking for a rendering engine alternative nor looking to be bombarded with advertisement on any of them. I didn't even mention which rendering engine I'm using. That means it is irrelevant. – ChuckE Aug 26 '13 at 11:19
1 Answers
0
If you're working from the Rails console, you could call:
> app.get '/'
> response = app.response
> body = response.body

RubeOnRails
- 1,153
- 11
- 22
-
nice feature! it can be useful in some ways, but I'm afraid I'll stumble into some issues whenever a view requires a user to be logged in for it to render the full response body I'd like to see. But this has been the closest to an answer to this issue I've seen. Do you know how I can mask a logged user session into it? – ChuckE Jan 16 '14 at 11:14
-
I didn't know you required logging in. There are a few ways to do so, but you may benefit most from posting another question. Depending on how you authenticate users, you could augment the controller in the console to `skip_before_filter`, you could alter `app.controller.current_user`, you could actually log in by posting to the appropriate routes, you could play with warden/rack middleware, you could alter `app.session`, etc. It depends on your implementation. – RubeOnRails Jan 16 '14 at 22:53
-
You may benefit from these related posts: * http://stackoverflow.com/questions/9544338/rails-3-how-can-you-get-access-to-devises-current-user-in-the-irb-console * http://stackoverflow.com/questions/6209663/how-to-skip-a-before-filter-for-devises-sessionscontroller – RubeOnRails Jan 16 '14 at 22:57
-
I think we are diverting now from the main topic. I'm not caring about handling the sessions, I want to render templates easily. – ChuckE Jan 17 '14 at 12:09