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
11
votes
1 answer

How to decorate nested attributes (associations) with Draper in Rails 3?

My environment: Rails 3.2 with draper gem I'm using nested resources and having trouble figuring out where to declare the decorator. #app/controllers/users_controller.rb def show @user = UserDecorator.find(params[:id]) @items =…
sethherr
  • 127
  • 2
  • 10
10
votes
2 answers

How to spec draper decorators with rspec.

I am attempting to write specs for the individual functions in my decorators. I have specs for my helpers like the following (this is just an example): book_helper.rb module BookHelper def heading_title @book.name[0..200] …
Zack
  • 2,377
  • 4
  • 25
  • 51
7
votes
2 answers

Rendering a partial from Draper Decorator

I have a decorator that returns either a string, or a collection. In my view, I want to display the return of this decorator method. class MyDecorator < Draper::Decorator def stuff if condition 'some string' else render…
ardavis
  • 9,842
  • 12
  • 58
  • 112
5
votes
2 answers

Using RABL with Draper to render to_json

I've got some fairly complex JSON responses in my application for my Ticket model and I'd like my TicketDecorator to be the one who builds those responses. However, I've already setup and API for my system and use RABL to build those JSON responses,…
TheDelChop
  • 7,938
  • 4
  • 48
  • 70
4
votes
2 answers

public_activity gem decorated with Draper

I'm trying to decorate a collection of activities created by the public_activity gem using Draper. However, it appears that PublicActivity::Activity doesn't inherit from ActiveRecord (am I right in assuming that?) so I need to add include…
niftygrifty
  • 3,452
  • 2
  • 28
  • 49
4
votes
2 answers

How can I access helper methods in my decorator spec files using Draper 0.14.0

Currently in my spec/decorators/product_decorator_spec.rb, I have the following: require 'spec_helper' describe ProductDecorator do let(:product) { FactoryGirl.create(:product) } subject do ProductDecorator.first end before do …
jklina
  • 3,407
  • 27
  • 42
3
votes
1 answer

Controller spec + draper

I'm using rspec and draper gem https://github.com/jcasimir/draper In my controller it's a simple action show def show @category = Category.find(params[:id]) @products = ProductDecorator.decorate(@category.products) end and test describe "#show"…
Ivan Linko
  • 966
  • 7
  • 15
3
votes
1 answer

Testing Draper-enhanced models using rspec

I have an rspec test for my view which worked fine before I abstracted out some of the logic using draper. The view renders correctly in the browser, but the test now fails. require 'spec_helper' describe "articles/index.html.erb" do …
John Y
  • 1,161
  • 12
  • 23
3
votes
2 answers

Could not find generator 'draper:install' rails 5

Using rails 5 I added the gem gem 'draper', '3.0.0.pre1' then when I call the install generator I get an error Could not find generator 'draper:install'. Maybe you meant 'devise:install', 'config:install' or 'responders:install' Anything Im doing…
saadlulu
  • 1,375
  • 2
  • 26
  • 38
3
votes
1 answer

Rspec issues with helper on decorator on view test

One of my rspec tests fails because I can't use a helper method on a decorator rendering a view, while the view works perfectly while running the server normally, here's the error 1) dashboard/index.html.haml render all translations …
Marcelo Risoli
  • 792
  • 7
  • 24
3
votes
1 answer

Handmade decorators in Ruby on Rails. When Drapper causes more problems than solves

I'm using Draper gem in my Rails project to obtain decorator pattern functionality. I thought that gem will help to increase my productivity by separating model logic and view logic. But overall workflow has become terrifying. I should always add…
Pavel Tkackenko
  • 963
  • 7
  • 20
3
votes
1 answer

Draper with Bootstrap Pagination - undefined method 'total_pages'

I'm using Draper to decorate my views and move some logic out of them but I'm struggling with this question - how to setup Draper with Bootstrap Pagination (will_paginate)? By default I have this: delegate_all And from Draper documentation I've…
3
votes
1 answer

How to access session variables from a Draper decorator in Rails?

I want to be able to access a session variable from the Decorator. Now I can't do so, nor can I access controller instance variables, let's say @session_variable. Is there a clean way to achieve this? Thanks!
3
votes
0 answers

Using rails draper gem with angularjs and json

so, I have seen people dancing around this topic, but I can't find the answer. I just installed the 'draper' gem with rails. It's great, but I want to be able to use it with angularjs. Is there a way to do that? Or do I need to just make a…
rikkitikkitumbo
  • 954
  • 3
  • 17
  • 38
3
votes
1 answer

How can I create a decorator for a set of models with use the same table?

I've got a Rails project which has a large set of models all using the same table through Single Table Inheritance. They are all different types of organisations. Is it possible to use the draper gem to simplify my model without the need to create a…
map7
  • 5,096
  • 6
  • 65
  • 128
1
2 3 4 5 6