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

How to avoid too many `h.concat` in decorater

I'm using a lot of h.concat in a Decorator class like this: def vote_box(size) h.content_tag(:div, class: "vote-box #{size}") do h.concat(h.link_to(h.up_vote_phrase_path) do h.concat h.content_tag(:span, '', class: 'glyphicon…
ironsand
  • 14,329
  • 17
  • 83
  • 176
0
votes
0 answers

How to call decorate method when I want to call it from another controller?

In user's home page I want to show the user's phrases. class StaticPagesController < ApplicationController def home if user_signed_in? @phrases = current_user.phrases.decorate end end end But this fails by Could not infer a…
ironsand
  • 14,329
  • 17
  • 83
  • 176
0
votes
1 answer

Rails 4, Draper: authenticated user and views

<% if user_signed_in? %> <% end %> This view pattern seems to not separate concerns. I wrap several views in my app with logic demanding the user is signed in and would instead like to separate concerns and put the <%…
brntsllvn
  • 931
  • 11
  • 18
0
votes
1 answer

How to decorate an object with another name in draper?

This is the question I have a Event model and a User model. An Event has one creator of class User. I used this line in Event model to associate it: belongs_to :creator, :class_name => "User" So I can access the creator through this…
hecontreraso
  • 1,221
  • 3
  • 15
  • 23
0
votes
1 answer

Rails draper gem with Ajax/JS

I'm using draper and want to use one of the decorators in a view. With HTML everything works, but decorators don't work in the Ajax version - I get an undefined method error. In CommentDecorator: delegate_all def comment_author "#{user.firstname}…
willyW
  • 5
  • 4
0
votes
1 answer

Why does decorator fail?

I have problem with my decorator: class ReviewDecorator < Draper:Decorator delegate_all def author @author = User.find_by(review.user_id) "#{@author.firstname} #{@author.lastname}" end end Every time I test this decorator, I receive…
Nekron
  • 123
  • 10
0
votes
1 answer

Draper Gem resulting in Undefined method error

I have used draper with some success. But currently I'm stuck. I have two models: # Foo.rb class Foo < ActiveRecord::Base has_many :bars # Bar.rb class Bar < ActiveRecord::Base belongs_to :foo def self.number_banned …
HermannHH
  • 1,732
  • 1
  • 27
  • 57
0
votes
1 answer

Rails Draper Gem raising undefined method for Nested Model

I have various associated model in my application. I have setup Draper to decorate associations upon initialization of the parent class. I have the following classes: Customer (has_many :accounts) Account (belongs_to :customer && has_many…
HermannHH
  • 1,732
  • 1
  • 27
  • 57
0
votes
1 answer

Using the Rails form builder and Draper

I'm giving Draper a try as an alternative to helpers. I get the cases where I am just formatting the information. But what about interacting with the Rails form builder. For example if I wanted to output a string or a select box depending on some…
Eric Anderson
  • 3,692
  • 4
  • 31
  • 34
0
votes
1 answer

How to decorates date format for 3 different fields using Draper decorator gem

I want to decorate my 3 dates using a decorator pattern, I did what steps are necessary for implementing the decorator pattern, I have written following code in the decorator to decorates my date fields def date1 …
Deepti Kakade
  • 3,053
  • 3
  • 19
  • 30
0
votes
1 answer

how to access a decorator Admin::ExampleDecorator in controller?

I have used draper gem to generate the decorator and I have crated a decorators. I have used namespacing inside decorator folder, and I tried to access the that decorator in specific controller with decorates_assigned. For example my folder…
Deepti Kakade
  • 3,053
  • 3
  • 19
  • 30
0
votes
1 answer

Draper causing text_field to output incorrect results

I'm using draper to clean up some view logic. I have some code as such: Decorator: class EventTypeDecorator < Draper::Decorator delegate_all def name_field if object.name == 'Miscellaneous' h.text_field object, :name, {id:…
Alex Vallejo
  • 1,331
  • 1
  • 12
  • 15
0
votes
1 answer

Draper and RSpec and Factory Girl Controller Specs on Rails 4 App

I am using Draper for the first time and it's working great...except for the fact that it broke most of my specs. An example: I am setting up an account_settings_controller_spec.rb describe '#create' do before do @user = create :user …
goddamnyouryan
  • 6,854
  • 15
  • 56
  • 105
0
votes
2 answers

undefined method error draper gem

I am trying to user draper gem and looks like I set up just fine, however, when I call method inside my draper method, I get an "undefined method error" Here is what I have done so far. gem 'draper' bundle install rails g decorator MyModel in my…
Harish
  • 1,469
  • 16
  • 43
0
votes
1 answer

Refactor view code to decorator using .each

I'm just learning how to move view code into decorators using the draper gem. I'm having trouble figuring out how to move .each into the decorator. <% @project.users.each do |p| %> <%= link_to…
prodigerati
  • 597
  • 8
  • 26