ruby on rails - Returning issue in Comment::ActiveRecord_Associations_Collection -


i'm trying display comments made user in user profile page (no matter if it's public or page behind login), i'm experiencing issue prints in app comment::activerecord_associations_collectionproxy:0x00000103c89750 (it's not error kills app, prints message).

the element commentable within app 'hacks', , users can create comments on each hack.

user.rb

      class user < activerecord::base       temp_email_prefix = 'change@me'       temp_email_regex = /\achange@me/       include gravtastic       gravtastic        # include default devise modules. others available are:       # :confirmable, :lockable, :timeoutable , :omniauthable       devise :database_authenticatable, :registerable,              :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :confirmable          validates_format_of :email, :without => temp_email_regex, on: :update        def self.find_for_oauth(auth, signed_in_resource = nil)          # identity , user if exist         identity = identity.find_for_oauth(auth)          # if signed_in_resource provided overrides existing user         # prevent identity being locked accidentally created accounts.         # note may leave zombie accounts (with no associated identity)         # can cleaned @ later date.         user = signed_in_resource ? signed_in_resource : identity.user          # create user if needed         if user.nil?            # existing user email if provider gives verified email.           # if no verified email provided assign temporary email , ask           # user verify on next step via userscontroller.finish_signup           email_is_verified = auth.info.email && (auth.info.verified || auth.info.verified_email)           email = auth.info.email if email_is_verified           user = user.where(:email => email).first if email            # create user if it's new registration           if user.nil?             user = user.new(               name: auth.extra.raw_info.name,               #username: auth.info.nickname || auth.uid,               email: email ? email : "#{temp_email_prefix}-#{auth.uid}-#{auth.provider}.com",               password: devise.friendly_token[0,20]             )             user.skip_confirmation!             user.save!           end         end          # associate identity user if needed         if identity.user != user           identity.user = user           identity.save!         end         user       end        def email_verified?         self.email && self.email !~ temp_email_regex       end        include thecomments::user        has_many :hacks       has_many :comments        def admin?         self == user.first       end        def comments_admin?         admin?       end        def comments_moderator? comment         id == comment.holder_id       end     end 

comment.rb

    class comment < activerecord::base        belongs_to :user        include thecomments::comment       # ---------------------------------------------------       # define comment's avatar url       # use comment#user (owner of comment) define avatar       # @blog.comments.includes(:user) <= use includes(:user) decrease queries count       # comment#user.avatar_url       # ---------------------------------------------------        # public       # ---------------------------------------------------       # simple way define avatar url       #       # def avatar_url       #   src = id.to_s       #   src = title unless title.blank?       #   src = contacts if !contacts.blank? && /@/ =~ contacts       #   hash = digest::md5.hexdigest(src)       #   "https://2.gravatar.com/avatar/#{hash}?s=42&d=https://identicons.github.com/#{hash}.png"       # end       # ---------------------------------------------------        # private       # ---------------------------------------------------       # define content filters       # gem 'redcloth'       # gem 'sanitize'       # gem 'mysmilesprocessor'       #       # def prepare_content       #   text = self.raw_content       #   text = redcloth.new(text).to_html       #   text = mysmilesprocessor.new(text)       #   text = sanitize.clean(text, sanitize::config::relaxed)       #   self.content = text       # end       # ---------------------------------------------------     end 

hack.rb

    class hack < activerecord::base        belongs_to :user          acts_as_taggable # alias acts_as_taggable_on :tags         acts_as_taggable_on :tags         has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }         validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]        #for commenting       include thecomments::commentable        # denormalization methods       # please, read advanced using       def commentable_title         "undefined post title"       end        def commentable_url         "#"       end        def commentable_state         "published"       end      end 

user view

            <p>               <strong>user email?:</strong>               <%= @user.email %>               <%= @user.comcoms %>             </p> 

the gem i'm using comments the_comments , there some docs here have read widely, , think @user.comcoms should return i'm looking not :/

@user.comcoms give comments related particular users(@user in case) commentable models. so, going return collection of comments , comment::activerecord_associations_collectionproxy:0x00000103c89750 showing reference of collection.

you need iterate on collection , display required fields instance of comment class.

replace

<%= @user.comcoms %> 

with

 <% @user.comcoms.each |comment| %>     <%= comment.raw_content %>     <%= comment.commentable_title %>     <%# add other attributes %>  <% end %> 

refer link added in question, attributes can accessed on comment comment api


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -