0

I'm working on a project with Events which are published to EventBrite. An Event has a number of fields (Bio, Image, etc...) which will published to EventBrite as a HTML blob. It feels dirty to generate HTML straight from the model and I think that I'd rather see something like how mailers are done, but it feels like I'm reinventing the wheel.

Any recommendations?

1
  • erb/haml provide templating but don't solve the issue that the Event model is being wired to a view. Commented Aug 27, 2012 at 12:41

1 Answer 1

3

You should use the decorator pattern.

An example is described in this Railscast.


# @param view_name [String]
# @param locals [Hash] containing the variables you want to pass to the view (I guess only the decorator itself)
def render(view_name, locals = {})
  filename = File.join "app", "views", "decorators", "#{view_name}.html.erb"
  template = File.read filename
  eruby = Erubis::Eruby.new(template)
  eruby.result locals
end
Sign up to request clarification or add additional context in comments.

6 Comments

+1 definitely agree. You've come across one of the flaws on MVC
@sethvargo: fully agreed to your comment
With Draper, its wouldn't it still be a case of the Model generating the view?
Not directly, but you could create your own method which will get an erb file in a dedicated folder and pass the variables to it. Would you like an example?
Thanks @apneadiving. erb examples are fairly abundant so I'm all set. I guess what I am trying to really figure out is whether its worth it to create something like a EventBriteDispatcher with a method that would take an Event and call to EventBrite.
|

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.