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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:08:38+00:00 2026-05-17T23:08:38+00:00

I have 2 models that correspond to 2 separate db tables. model 1: status

  • 0

I have 2 models that correspond to 2 separate db tables.

model 1: status updates of a user ex. ( comment: hello | username: marc)
model 2: restaurant names that a user has eaten at ( restaurant: KFC | username: marc)

I have 1 view that shows restaurant websites generated from a Google search. A hidden form is also generated for each restaurant listed. When the user presses the “I ate here!” button, it submits this hidden form to the restaurants controller, then model 2, recording the users name and the resturant he ate at.

I want to use the “I ate here!” button to ALSO post a status update of the restaurant name to model 1.

this should be done with fields_for, but the 2 models don’t have a relationship with each other.. that I see..

How can I make this happen?

here is my pastie: http://www.pastie.org/1280923

I hope thats clear!

  • 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-17T23:08:38+00:00Added an answer on May 17, 2026 at 11:08 pm

    There’s no such thing as “submits the form to a model”. Forms are always submitted to your controller.

    With that in mind, you can just override the create or update method on your controller to perform any action you want.

    Your controller will look like this:

    class RestaurantsController < ApplicationController
      def update
        @restaurant = Restaurant.find(params[:id])
        unless @restaurant.update_attributes(params[:restaurant])
          # error while saving: warn user, etc
          return # stops execution
        end
    
        # restaurant was saved ok, do the additional things you want
        StatusUpdate.create :user_id => @restaurant.user_id, 
                            :comment => "I just ate @ #{@restaurant.name}"
    
        flash[:notice] = 'Restaurant was successfully updated, and a status update was added.'
        redirect_to :action => 'list'
      end
    end
    

    However, if your scenario is as simple as it looks, you can also solve this using an ActiveRecord callback on your model:

    class Restaurant < ActiveRecord::Base
      after_save :append_status_update
    
      private
    
      def append_status_update
        StatusUpdate.create :user_id => self.user_id, 
                            :comment => "I just ate @ #{self.name}"
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.