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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:16:09+00:00 2026-06-14T09:16:09+00:00

How do I solve the following issue: I want to add a new row

  • 0

How do I solve the following issue:

I want to add a new row to the table submitted_pictures, which is linked as follows:

game.rb
    has_many :rounds
    has_many :participants, :dependent => :destroy
    has_many :submitted_pictures, :through => :rounds
    has_many :users, :through => :participants
    accepts_nested_attributes_for :participants
    accepts_nested_attributes_for :rounds, :reject_if => :all_blank

round.rb
    belongs_to :game
    has_many :submitted_pictures, :dependent => :destroy
    accepts_nested_attributes_for :submitted_pictures

submitted_picture.rb
    has_one :round
    has_one :game, :through => :rounds
    belongs_to :user

So I could call:

<% @user.games.rounds.last.submitted_pictures.each do |blabla| %><% end>

I made a complex form using:

<%= form_for(@game) do |f| %>
    <%= f.fields_for :round do |ff| %>
        <%= ff.fields_for :submitted_pictures do |fff| %>
            <%= fff.label :flickr_id %>
            <%= fff.text_field :flickr_id %>
        <% end %>
    <% end %>
    <%= f.submit "Submit Picture", class: "btn btn-primary" %>
<% end %>

Hoping to add a new submitted_picture with the flickr_id (which holds a httplink for now), linked to the the current game (@game).

I’ve been trying several things to update it but it doesnt seem to budge: (the update_attributes is totally wrong I see now :p)

def update
    @game = Game.find(params[:id])
    if @game.rounds.last.submitted_pictures.update_attributes(params[:id])
        flash[:success] = "Pic Submitted!"
    else
        render :action => 'new'
    end
end

Also

def update
    @game = Game.find(params[:id])
    if @game.save
        flash[:success] = "Pic Submitted!"
        redirect_to games_path
    else
        render :action => 'new'
    end

end

I can’t get it to work. I’m getting all kinds of errors, so instead of noting them all here I thought it would be best to ask for the best solution.

So in short, I’m wanting to add a submitted_picture to the latest round (most recent created_at) of the game.

  • 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-14T09:16:10+00:00Added an answer on June 14, 2026 at 9:16 am

    I think nesting everything in a game form is making things unnecessarily complicated for you. If I understand correctly, you want to create a new submitted_picture and it needs to have a game selected. The round is not directly selected, but is just the latest for the game. (this sounds like a suspicious assumption–but it does keep things simpler so I’ll roll with it)

    So just make a new submitted_picture form, and add in a game select.

    In your handler, pull the latest round from the game and merge that round into your params to save the new picture.

    Does that do what you want?

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

Sidebar

Related Questions

I am getting the following error, when I want to add new UserProfile using
I want to solve the following optimization problem: Non-Latex: Given x and mu, find
I am trying to solve the following question : A sequence in which the
I am trying to solve the following question which was part of a programming
In my android application I want to solve the following scenario. class Login extends
How would you solve the concurrency issue with the following code? In this example,
I am new to C# and WPF. I want to do the following :
My regular expression knowledge is lacking and I'm trying to solve the following issue.
I'm having the following issue with WCF RIA Services: I have a table Customer
I have the following issue to solve. I have an IQueryable list of Invoices,

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.