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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:22:14+00:00 2026-06-01T16:22:14+00:00

I have a Threads controller and Messages controller. Threads has_many Messages Once a user

  • 0

I have a Threads controller and Messages controller.

Threads has_many Messages

Once a user clicks send, I send data into Threads controller to create the thread. I want to make it to so that

threads_controller.rb

def create
    ...
    if @thread.save
         #send data into messages_controller 
         #to create the corresponding table for a message with this thread_id

end

So, essentially I am trying to do two POSTS one after another if the first one succeeds.

I think redirect_to is what I am supposed to use. Is it possible to use redirect_to to pass params and call create action from a different controller?

EDIT:
I have to have a Thread(bad name choice for the reason Ryan mentioned, but for the sake of not confusing people with answers on the bottom, let’s keep it) Model and Message Model here. Thread table needs to only take in the message_title. The Message table takes in from_id(id of user sending message), to_id(id of user receiving message), and message_content. I am trying to do all of this in one form that takes in message_title and message_content.

I hope this helps in understanding the question.

Thanks everyone

  • 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-01T16:22:15+00:00Added an answer on June 1, 2026 at 4:22 pm

    I think you’re going about this in the wrong way.

    First: I really hope that you’re not calling a model Thread, as that would conflict with the Ruby class Thread. If you are, choose a different word.

    Now with the “please aim the gun away from your foot” message out of the way…


    You shouldn’t be calling out to the MessagesController to create a new message for the controller. Instead, you should be using nested attributes in the new thread form:

    <%= form_for @thread do |f| %>
      <%= f.fields_for :messages do |message| %>
        <%= render "messages/form", :message => message %>
      <% end %>
    <% end %>
    

    Inside your DiscussionThread (I am assuming the name of it here) model, you would then have these lines:

    has_many :messages
    accepts_nested_attributes_for :messages
    

    You may have to add messages_attributes to the attr_accessible attributes in this model too.

    This tells the DiscussionThread model that instances can accept attributes for the messages association too. In your ThreadsController the action would then remain the same.

    For more information about nested attributes, I recommend watching the Railscasts on Nested Forms #1 and Nested Forms #2.

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

Sidebar

Related Questions

I have two threads, a producer thread that places objects into a generic List
I have 2 threads and global Queue, one thread (t1) push the data and
I have two threads running from a controller class. The first thread receives SMS
I have two threads in an Android application, one is the view thread, and
I have two threads referencing the same variable -- the UI thread and a
I have multiple threads that share use of a semaphore. Thread A holds the
I'm trying to use broadcasters to send messages from a child thread to the
Hello I have the following in my Create Controller: def create @requestable = find_requestable
I have two threads, one needs to poll a bunch of separate static resources
I have two threads, one updating an int and one reading it. This is

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.