Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 790229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:39:00+00:00 2026-05-14T21:39:00+00:00

I have in my model: def presenter @presenter ||= ProfilePresenter.new(self) @presenter end The ProfilePresenter

  • 0

I have in my model:

def presenter
   @presenter ||= ProfilePresenter.new(self)
   @presenter
end

The ProfilePresenter is a class that has methods like, get_link(), get_img_url(size), get_sex(), get_relationship_status() and other methods that have not to do with the model, not even with the controller but is used multiple times in the view.

So now i use them by doing this:

Profile.presenter.get_link
# or
Profile.presenter.get_img_url('thumb') # returns the path of the image. is not used to make a db query

Sincerelly i think i missed out the real concept of presenters.. but this is what m trying to archive, how can be called this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:39:00+00:00Added an answer on May 14, 2026 at 9:39 pm

    Normally this sort of thing is handled via helper methods, such as:

    def profile_link(profile)
      profile.link ? content_tag(:a, h(profile.name), :href => profile.link) : 'No profile'
    end
    

    It is unfortunate you cannot layer in Presenter-style helper methods that extend a Model at view time. They need to be called in a procedural manner with a parameter, kind of anti-OO.

    The Presenter approach is not fully supported in the Rails MVC area because it needs to bind to a view in order to have access to the various helper methods required to properly render content, plus information about the session that may impact the presentation.

    A more robust approach might be to do something like this:

    class ProfilePresenter
      def initialize(view, profile)
        @profile = profile
        @view = view
    
        yield(self) if (block_given?)
      end
    
      def link
        @profile.link ? @view.content_tag(:a, @view.h(profile.name), :href => @profile.link) : 'No profile'
      end
    
      def method_missing(*args)
        @profile.send(*args)
      end
    end
    

    This would show up in your view as something like:

    <% ProfilePresenter.new(self, @profile) do |profile| %>
    <div><%= profile.link %>
    <% end %>
    

    You can simplify calling this by making a helper method that does something mildly crazy like:

    def presenter_for(model)
      "#{model.class}Presenter".constantize.new(self, model) do |presenter|
        yield(presenter) if (block_given?)
      end
    end
    

    This means you have a much simpler call:

    <% presenter_for(@profile) do |profile| %>
    <div><%= profile.link %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model, smth like this: class Action(models.Model): def can_be_applied(self, user): #whatever return
So, say I have models like this: class Foo(Model): name = CharField(max_length=200) def latest_comment(self):
In my model I have: class Log < ActiveRecord::Base serialize :data ... def self.recover(table_name,
I have methods in all of my models that look like this: def formatted_start_date
I have a Model like this: class MyModel attr_accessor :size end Now i want
I have my mongoid query in the model def self.get_result collection_name, hash_params, page, per_page
I have a model with an __init__ method: class Foo(models.Model): name = models.CharField(max_length=50) def
I have a model, for example : class Account < ActiveRecord::Base before_create :build_dependencies def
I have the following abilities model: class Ability include CanCan::Ability def initialize(user) user ||=
I have a simple model: class User < ActiveRecord::Base has_and_belongs_to_many :roles end class Role

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.