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
1
vote
0 answers

How can I use an application decorator for site-wide view logic?

After watching the recent Railscasts episode on Draper I thought I'd have a go at refactoring some of my stuff to make use of the Decorator pattern. And then instantly managed to confuse myself. I have view logic in my application layout file that…
DDubyah
  • 53
  • 7
1
vote
0 answers

How to add color and drape to 3D plot

I have used the following code: import numpy as np import matplotlib.pyplot as plt def f(x, y): return ( ((np.log(x**2) / np.log(y**3)) / x**2 )*500) x = np.linspace(0, 600, 4) y = np.linspace(0, 1000, 4) X, Y = np.meshgrid(x, y) Z =…
Giampaolo Levorato
  • 1,055
  • 1
  • 8
  • 22
1
vote
1 answer

Draper::UninferrableDecoratorError (Could not infer a decorator)

I want to infer a decorator in a controller, so I generate a decorator the normal way (rails g decorator) and infer it in the controller. However, when I test with Postman, I get the error: Could not infer a decorator for Employers::Job. The error…
TPR
  • 101
  • 6
1
vote
1 answer

Rails Draper's Decorator caused ArgumentError

I set up Draper's Decorator for a Rails project to replace the original helper. I moved the helper code to the Decorator: def birthday(date) "MinYear#{date.year - 1911} Month#{date.month} Day#{date.day}" end And add .decorate text in View to use…
Ckt22
  • 181
  • 1
  • 1
  • 9
1
vote
0 answers

How to use draper and cancancan?

Trying to use can? method and stub current ability. class UserDecorator < Draper::Decorator delegate_all def some_helper can? :read, object end end RSpec.describe UserDecorator, type: :decorator do before { allow(subject).to…
Chiara Ani
  • 918
  • 7
  • 25
1
vote
1 answer

Can't install and use "draper" gem

I have some problems handling draper gem. install draper gem 'draper' $ bundle install and this was successful. did rails generate draper:install $ rails generate draper:install but I got some errors Expected string default value for…
Hiromu Masuda
  • 259
  • 1
  • 3
  • 14
1
vote
1 answer

How to use decorator in rails correctly?

I'm newbie in using decorators and I need your help to understand how to use it right and what am I doing wrong. book_decorator.rb class BookDecorator < ApplicationDecorator delegate_all def in_users_list?(user) if user.books.exists? …
Jakov
  • 151
  • 13
1
vote
1 answer

rails method from multiple methods

So I have this code in my Rails presenter(similar to Draper gem): def title h.link_to 'Favor', favor_path(@favor) + asked_or_published? + user_link end def asked_or_published? if asked_favor? h.content_tag(:p, "published by") …
fardin
  • 1,399
  • 4
  • 16
  • 27
1
vote
1 answer

ActiveAdmin not decorating show view

I am using ActiveAdmin on my Rails project. I use Draper as decorator but I don't understand why the show view is not decorated. According to the documentation it should be working just adding the decorate_with MyDecorator in my ActiveAdmin…
anthony
  • 640
  • 1
  • 10
  • 32
1
vote
0 answers

draper decorator changed the 'model' attribute from original model Rails

I am implementing draper decorators and below is the code. def edit find_machine! puts @machine.model authorize! :edit, @machine end def find_machine! @machine = Machine.find(params[:id]) end Everything works fine before I added…
Chris Yeung
  • 2,613
  • 6
  • 34
  • 57
1
vote
0 answers

Raw and simple_form...neither is perfect

I have this in one of my models: def rank_match_2 ... ... array = [start, finish, [words]] results = field.insert(start, "") and field.insert(finish, "") ... end Now I know I shouldn't be adding view logic in the model, but I am…
MarkD
  • 65
  • 1
  • 7
1
vote
1 answer

Trouble implementing ajax. if statement wont work

I'm not sure what the problem is here to know what exactly I'm asking but I'll give it my best shot. I tried to bold where I think the issues is to make it clearer. I'm working with ajax for the first time. In the app a user(1) searches for…
sss333
  • 105
  • 2
  • 13
1
vote
1 answer

Is there anything bad about decorating objects (using Draper) at the start of a view?

Draper recommends decorating objects at the end of a controller method or alternatively using their decorates_associated method to automatically decorate them. I like the idea of the view explicitly declaring what it expects to receive (granted the…
Peter Nixey
  • 16,187
  • 14
  • 79
  • 133
1
vote
1 answer

Error while using draper generator

I got a problem while generating draper. When I use rails g draper:decorator user I got this : Could not find generator draper:decorator. I got draper in gem file and made bundle install. Any suggestions ? Thanks,
user3564349
  • 31
  • 1
  • 4
1
vote
1 answer

Inherited Resources and Draper

How to use Draper with Inherited Resources? In other words, how to call the method(#decorate) for each resource? For example @posts for #index, @post for #show? I thought about default_scope, but everything related with Draper needs to be in the…
just so
  • 1,088
  • 2
  • 11
  • 23