How to render erb template to string inside action?

前端 未结 4 1701
囚心锁ツ
囚心锁ツ 2020-12-16 14:52

I need a string of html (something like \"Hello World\") for faxing purpose.

I wrote it into a seprat

4条回答
  •  囚心锁ツ
    2020-12-16 15:34

    If you don't want to escape html, just call .html_safe on it:

    "Hello World".html_safe

    Re your error, please post your OrdersController - looks like you are calling render or redirect more than once in the create action.

    (Btw, just in case you are trying it - you can't render a partial in a controller - you can only render partials in views)

    Edit: yeah your problem is you trying to render a partial in the controller action. You could use an after_create callback to set up and send the fax - though again you won't want to use a partial (as they are for views). http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

    Edit: for your fax problem,you could create a normal Ruby Class, see this excellent bit of advice from Yehuda: https://stackoverflow.com/a/1071510/468009

提交回复
热议问题