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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:52:22+00:00 2026-06-10T03:52:22+00:00

I have a model Messages, for which I have a recipient_list which saves as

  • 0

I have a model Messages, for which I have a recipient_list which saves as a string. For whatever reason on save, all of my parameters other than the recipient_list are being saved, with only the recipient_list being left out. I’m stumped as to what the cause for this may be.

Model:

class Message < ActiveRecord::Base
  attr_accessible :content, :sender_id, :recipient_list
  attr_reader :recipient_list #necessary for jquery-token-input

  belongs_to :sender, class_name: "User"

  validates :content, presence: true
  validates :sender_id, presence: true
  validates :recipient_list, presence: true

  def recipient_list=(recipient) #jquery-token-input
    self.recipient_ids = recipients.split(",")
  end

end

Controller:

def create
  @message = current_user.sent_messages.build(params[:message])
  if @message.save
    flash[:success] = "Message Sent."
    redirect_to '/users/'+current_user.id.to_s+'/messages'
  else
    redirect_to '/users/'+current_user.id.to_s+'/messages'
  end
end

Parameters:

{"utf8"=>"✓",
"authenticity_token"=>"WlStV4ogguSX72vrZp10zJbucS5MTL1pT1DLt06qjcw=",
"message"=>{"recipient_list"=>"1,2",
"content"=>"foobar123",
"sender_id"=>"1"},
"commit"=>"Send"}

Result:

#<Message id: 32, content: "foobar123", sender_id: 1, recipient_list: "", created_at: "2012-08-22 19:38:44", updated_at: "2012-08-22 19:38:44">] 

What might be the problem that is keeping the recipient_list from being saved in this case?

Edit:

Par Ylan’s note I set out to see why it was working despite the difference in variable name.
upon messing with it, I realized that it actually was only working that way if i made recipient -> recipients or the reverse the it would stop working.

Fiddled with it, and based on Nash’s suggestion came up with the following:

def recipient_list=(ids)
 recipient_list = ids.split(",")
 super(recipient_list)
end


#<Message id: 42, content: "foobar123", sender_id: 1, recipient_list: "---\n- '1'\n", created_at: "2012-08-22 21:58:46", updated_at: "2012-08-22 21:58:46">] 

So now the recipient_list is being saved, I just have to figure out how to remove all the unecessary garble and get just the ‘1’ lol. Any further suggestions?

Edit #2:
After adding
serialize :recipient_list, Array

#<Message id: 43, content: "foobar123", sender_id: 1, recipient_list: ["1", "2"], created_at: "2012-08-22 22:10:46", updated_at: "2012-08-22 22:10:46">] 

is the new out put which is what i was going for. We worked together on this one. Thanks you two.

  • 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-06-10T03:52:23+00:00Added an answer on June 10, 2026 at 3:52 am

    looks like you should call super method in your overriden writer:

    def recipient_list=(recipients) #jquery-token-input
      self.recipient_ids = recipients.split(",")
      super(recipients)
    end 
    

    or something similar depends on your code.

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

Sidebar

Related Questions

For instance, I have a model class which handles receiving bluetooth messages from other
For my application I have a method in my Messages model which returns all
I have a model Messages which I use to store messages throughout the site.
I have set up a UDP client/server model that can send string messages to
So I have a Conversation model, which has_many messages . I'm trying to create
I have a model User which has_many :messages and Message which belong_to :user. when
I have model with a location, which itself has a latitude and longitude. What
I have model Foo which has field bar. The bar field should be unique,
I have got an Entity model which contains a collection of Message objects which
I have a notices model which contains records of notices for each user. Each

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.