简体   繁体   中英

render a partial inside a model rails 3.2

I understand advice available on the net to never, ever, ever render in a model, for this case I need do it

 class Order
    def canceled_order_message(order)
            admin = User.find_or_create_by(email: "myemail")
            message = Message.new(subject: I18n.t(".buyer_has_canceled_the_order"), 
                      body: "#{render_to_string :partial => 'users/messages/templates/sent_by_admin/canceled_order', :locals => {:order => order}}")
            message.send_message
            message.save
    end
 end

I need render inside message body attribute:

render_to_string :partial => 'users/messages/templates/sent_by_admin/canceled_order

How can I do it?

Thank you!

Please check my answer here:

undefined method `fragment_for' for nil:NilClass on render partial with cache

I think that could be useful.

PS Horrible idea, please rethink your architecture.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM