Questions tagged [draper]

Decorators/View-Models for Rails Applications

Draper is a gem that adds an object-oriented layer of presentation logic to your application.

Without Draper, this functionality might have been tangled up in procedural helpers or adding bulk to your models. With Draper decorators, you can wrap your models with presentation-related logic to organise - and test - this layer of your app much more effectively.

84 questions
3
votes
1 answer

How can I disable the Draper decorator generator?

In my Rails 3.2 app's application.rb I have the following lines to disable scaffold generators I don't want: module MyApp class Application < Rails::Application # rest of the config... config.generators do |g| g.helper false …
Simon
  • 1,716
  • 1
  • 21
  • 37
3
votes
0 answers

Draper: How to convert all allowed attributes and public methods of the decorated model into json

I'm looking for an easy way to convert decorated model into json to use in my client-side templates. I'd like to find a solution where all allowed attributes and public methods of the decorated model will persist in json. Currently I have backbone…
Ortepko
  • 371
  • 1
  • 10
3
votes
1 answer

Draper - NoMethodError with RSpec testing for decorator

I'm receiving the following error when trying to test with Draper: NoMethodError: undefined method 'with_unit' for nil:NilClass Here's my test code: # spec/decorators/food_decorator_spec.rb require 'spec_helper' describe FoodDecorator do before…
Nick
  • 9,493
  • 8
  • 43
  • 66
2
votes
2 answers

Test view by rspec with draper Decorator

I try test my view with Rspec. In my view, I have a Decorator generate by Draper. This Decorator is expose by decent_exposure gem. I create my rspec test like that : require 'spec_helper' describe "boats/show.html.slim" do let(:boat_decorate) {…
shingara
  • 46,608
  • 11
  • 99
  • 105
2
votes
1 answer

Undefined method exists? for Draper::CollectionDecorator

I am trying to implement the Draper gem for my Rails project and having trouble getting it to work. I'm getting the error message: undefined method `exists?' for #Draper::CollectionDecorator:0x000055b625da7a10> The error seems to be coming up from…
Kevin Custer
  • 576
  • 1
  • 5
  • 13
2
votes
1 answer

Rspec and Draper : unitialized constant on class name

On Rails 4 when I execute rspec tests for a decorator I got the following error : /app/spec/decorators/my_decorator_spec.rb:3:in `': uninitialized constant MyDecorator (NameError) I'm surely missing something but I don't know…
vincentp
  • 233
  • 4
  • 17
2
votes
2 answers

Using draper gem with devise registration controller

I have declared user_decorator.rb instead of user_helper.rb in the following way class UserDecorator < Draper::Decorator delegate_all def contract_type contract_types.keys.collect {|k| [k.humanize, k]} end def employee_type …
2
votes
1 answer

How can I better test equality for decorated objects?

I'm having trouble with equality matchers in RSpec and Draper decorated objects. Specs to show what's going on: context 'how to use the right equality matcher' do let(:page) { build(:page) } let(:decorated_page) { page.decorate } it "should…
Lucy Bain
  • 2,496
  • 7
  • 30
  • 45
2
votes
1 answer

undefined method on decorated instance

Here is a decorator app/decorators/campaign_decorator.rb class CampaignDecorator < Draper::Decorator delegate_all Campaign::Campaign def created_at helpers.content_tag :span, class: 'time' do object.created_at.strftime("%a %m/%d/%y") …
Amit Patel
  • 15,609
  • 18
  • 68
  • 106
2
votes
3 answers

How can I decorate STI models with modularized decorators using Draper?

I'm using Draper for general view-layer decorators. I have some console-related, human-readability functionality I'd like to pull into new decorators. My first thought was to put them in a module, e.g., Human::XxxDecorator, keeping them isolated…
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
2
votes
1 answer

Provide class to be decorated by Draper

In pre 1.0 versions of the draper gem we were able to use the decorates method explicitly specifying the class to be decorated (e.g. when the class is namespaced): MyClassDecorator < Draper::Base decorates :my_class, :class => Namespace::MyClass …
Alexander Presber
  • 6,429
  • 2
  • 37
  • 66
2
votes
1 answer

draper - Help understanding delegate with "to" and "prefix"

Given that I have a class that inherits from Draper::Decorator, like this: class PageDecorator < Draper::Decorator delegate_all delegate :title, :name, :region, :keys, to: :glass_decorator, prefix: :glass def full_title …
yanhan
  • 3,507
  • 3
  • 28
  • 38
2
votes
1 answer

Draper with form_for in method

I am trying to create a method in a draper decorator that will spit out a form_for. I have a form that i'm using for searching records on the index view and have dozens of resources, so I really want to maintain this logic in one place if possible…
Sean
  • 1,078
  • 14
  • 25
2
votes
1 answer

Is it possible to validate the context in a Draper decorator?

I've started working with decorators at my new job and am finding them really helpful. I'm working on writing specs for one of our decorators and wondered if it was possible to do this... Setup (the stripped down version): We have a main object with…
Lucy Bain
  • 2,496
  • 7
  • 30
  • 45
2
votes
1 answer

Passing argument to decorator from controller in Rails using Draper

I couldn't figure out how to pass an argument to a decorator from a controller: The decorator: def as_json(options = nil) { :name => user.name, :dob => user.dob :created_at => user.created_at, :url => user } end The…
Diogo Andre
  • 658
  • 5
  • 17