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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:19:41+00:00 2026-05-23T04:19:41+00:00

Basically, I have an Events model and an EventSets model. Events have EventSets (where

  • 0

Basically, I have an Events model and an EventSets model. Events have EventSets (where applicable) so I can list and group them accordingly in the app (say, a set of Concerts in the Park events where each individual concert event has slightly different attributes, but most of the data are common to all events in that set).

I have the necessary associations in place so that I can designate an EventSet in Events#new.

In my EventSet model, I have a few columns of ‘default’ information (common location, common name, etc.) that I’d like to use to pre-populate fields in Events#new.

The EventSet for a new event is designated by a select field (which lists all EventSets, pulled from the EventSets table).

Is there a standard way of handling this in Rails 3 (w/ jQuery)? Or should I roll my own jQuery/AJAX fix to handle it? (I like to stick with the sensible defaults where appropriate.)

Edit for clarification: I’m trying to pre-populate form fields while still in the /events/new view before the form is submitted (as soon as an EventSet is selected). This is necessary because the EventSet-designated ‘defaults’ will often be overriden for a given Event… they’re just a starting point to save on input repetition for the user.

  • 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-23T04:19:41+00:00Added an answer on May 23, 2026 at 4:19 am

    Use the after_initialize callback

    def after_initialize :copy_stuff
    
    def copy_stuff
      return unless self.new_record?
      @event_set = EventSet.find(...)
      self.field1 = @event_set.field1
      self.field2 = @event_set.field2
    end
    

    You could also do something similar in the Controller.

    def new
       @event_set = EventSet.find(...)
       @event = Event.new(:field1 => @event_set.field1, :field2 => @event_set.field2)
       ...
    end
    

    EDIT

    You’ll need to grab those fields via an ajax request

    routes.rb

    post '/get-eventset-fields' => 'events#event_set_fields', :as => :get_eventset_fields
    

    events_controller.rb

    def event_set_fields
      @event_set = EventSet.find_by_id(params[:eventset_id])
      render :json => @event_set.to_json
    end
    

    new.html.erb

    var mycallback = function(data){
       $('#event_field1').val(data.field1);
       $('#event_field2').val(data.field2);
    }
    
    $("#eventset_select").change(function(){
       $.post('<%= get_eventset_fields_path %>', {'eventset_id': $(this).val()}, mycallback, "json"); 
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does jquery/javascript have any event model that you can attach to your objects? Basically
Basically what I'm trying to do is have a picture rotate using mouse events.
I basically have a server set up and I'm accepting new clients(UNIX) and i'm
I basically have to do a update of a record. I have a set
I have a TreeView whose ItemsSource is set to a Model I have. 3
Basically, I have a reasonably large list (a year's worth of data) of times
I basically have a program that filters records from one excel file to another
I basically have three tables, posts, images and postimages (this simply contains the ids
I basically have a unix process running and it is doing some heavy processing
I basically have the following string in the format: A,B,C:D,E,F What I am trying

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.