Ruby on Rails Thursday, October 28, 2010

David Kahn wrote in post #957906:
> On Thu, Oct 28, 2010 at 4:38 PM, David Kahn
> <dk@structuralartistry.com>wrote:
>
>>> > av = ActionView::Base.new(Rails::Configuration.new.view_path)
>>>
>>> Did you perchance want render_to_string (which also exists in Rails 2)?
>>>
>>
>> Hmmm... yup, that works, thanks. Would rather do that in the model but I
>> can pass it in and step aside from this mess. I must have been hankering for
>> punishment in doing it the way I did it in the first place.
>>
>
> Actually just discovered the reason I tried to do this in the model: I
> need
> to render this view to string from other controllers/models.

You should never be rendering anything from a model. Any rendering --
at all -- is the responsibility of the controller and view.

> Do you know
> offhand if I can just instantiate this controller and still call one of
> it's
> methods to string from a different controller or even better from a
> model?

render_to_string :controller => 'some_other_controller', :action =>
'export_file'

That should be all you need, just like plain old render. Does that not
work?

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment