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 7409165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:02:21+00:00 2026-05-29T06:02:21+00:00

We are looking to have Sender and Receiver attributes for each micropost that is

  • 0

We are looking to have Sender and Receiver attributes for each micropost that is entered on our site. The sender of the post, and the receiver whom it is directed to.

In other words, on each micropost that each user sees, we want the content, and just above or below the content of the post we want the sender shown and receiver shown. We also want users to be able to click on either the sender or the receiver and be linked directly to that profile.

How can we go about doing this? We are relatively new to rails and think additions need to be made in the Micropost model for this change to work. Or should the changes be made in the MicropostsController?

Micropost Model:

class Micropost < ActiveRecord::Base
  attr_accessible :content, :belongs_to_id

  belongs_to :user


  validates :content, :presence => true, :length => { :maximum => 240 }
  validates :user_id, :presence => true

  default_scope :order => 'microposts.created_at DESC'

    # Return microposts from the users being followed by the given user.
    scope :from_users_followed_by, lambda { |user| followed_by(user) }

    private

      # Return an SQL condition for users followed by the given user.
      # We include the user's own id as well.
      def self.followed_by(user)
        following_ids = %(SELECT followed_id FROM relationships
                      WHERE follower_id = :user_id)
        where("user_id IN (#{following_ids}) OR user_id = :user_id",
              { :user_id => user })
    end
  end

MicropostsController:

class MicropostsController < ApplicationController
  before_filter :authenticate, :only => [:create, :destroy]

  def create

    @micropost  = current_user.microposts.build(params[:micropost])
    if @micropost.save
      flash[:success] = "Posted!"
      redirect_to current_user
    else
     @feed_items = []
     render 'pages/home'
    end
  end


  def destroy
      @micropost.destroy
      redirect_to root_path
    end
end
  • 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-29T06:02:25+00:00Added an answer on May 29, 2026 at 6:02 am

    To eliminate some confusion and make it a bit more railsy, I’d go with:

    class Micropost < ActiveRecord::Base
      belongs_to :sending_user, :class_name=>"User", :foreign_key=>"user_id"
      belongs_to :receiving_user, :class_name=>"User", :foreign_key=>"belongs_to_id"
    end
    

    this will allow something like this in your view for a given Micropost object “@micropost”:

     <%= link_to(@micropost.sending_user.username, user_path(@micropost.sending_user)) %>
    
     <%= link_to(@micropost.receiving_user.username, user_path(@micropost.receiving_user)) %>
    

    *this assumes several things about the user object and routing, but should get you on the right path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to have a collection of objects that implement a certain interface, but
I'm looking to have it so that if someone enters information in a form,
Evening all. I have the following code that I need looking into - basically
I have a setup in which some applications communicate with each other via Tibco
I have an app that crawls a network looking for movies, their titles, length
Hi and thanks for looking! Background I have a computing task that requires either
Looking to have a database query set all the instance variables in a class:
Im looking to have a common parent function like so void main (param 1,
Im looking to have a login system on my asp.net mvc website and at
I have a text field and am looking to have if be valid for

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.