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

In my model I have: validate :my_custom_validation def my_custom_validation errors.add_to_base(error message) if condition.exists? end
If you have a controller method like so: @expose(json) def artists(self, action=view,artist_id=None): artists=session.query(model.Artist).all() return
I have a model, Thing, that has a has_many with ThingPhoto, using Paperclip to
Let's say I have a model like this class Foo(db.Model): id = db.StringProperty() bar
Let's assume I have a model called product. Let's assume that product has three
I have a simple model: class User < ActiveRecord::Base has_and_belongs_to_many :roles end class Role
I have written a function having the following signature: def action_handler(request, model): This action_handler
I have a model being populated by my data layer and then I have
I have some model objects I'm using in my Java client application. Later these
I have a model Question with a field called userid , before one ask

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.