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

  • Home
  • SEARCH
  • 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 6599875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:32:54+00:00 2026-05-25T18:32:54+00:00

I try to make a simple message controller with new/create actions, when I call

  • 0

I try to make a simple message controller with new/create actions, when I call new action I give through query string the to_id param,

/messages/new?to_id=1

that contains id of recipient, now my code is:

def new    
    @message = Message.new    
    @message.to = User.find(params[:to_id])
  end

  def create 
    @message = Message.new(params[:message])
    @message.from = current_user

    respond_to do |format|
      if @message.save
        format.html { redirect_to messages_path }
      else 
        format.html { redirect_to common_error_path, :notice => "failed to send message" }
      end   
    end
  end

It’s pretty default, my problem is that the changes in @message object that have been made in new action are not available in create action and I lose my to_id value, the first thing come to my mind is to store to_id value using session object, but I think it’s not the best idea, maybe someone have better solution for 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-25T18:32:55+00:00Added an answer on May 25, 2026 at 6:32 pm

    You’ll need to pass that parameter back with the POST on create. For example, if you have a

    belongs_to :to, :class_name => 'User'

    association on your Message model, you could do

    app/views/messages/new.html.erb

    <%= form_for @message do |f| %>
       <%= f.hidden_field :to_id %>
       ...
    <% end %>
    

    The above assumes you’ve kept your new action the same. Now, on your create action, your params[:message] would be equal to {:to_id => 1} and would assign it properly.

    Does that make sense?

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

Sidebar

Related Questions

I wanted to make some simple file recovery software, where I want to try
I'm fairly new to C# but I will try to make this quick! ;)
I will try to keep it simple: In my main activity I make a
I am trying to make a fairly simple call using PICC18. Using the MPLAB
I've a simple form <form action=try.php method=POST> <input id=name name=name type=text placeholder=Name /> <input
I'm trying to make things simpler. Here is my code: If Threading.Monitor.TryEnter(syncRoot) Then Try
I try to make a registration form. When user post the fields, i check
I'll try to make this as straight forward as possible. Currently our team has
When I try to make a very large boolean array using Java, such as:
I will try to make this as clear as I can, but if you

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.