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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:03:16+00:00 2026-06-09T18:03:16+00:00

Initially I created Exercises to browse. Then I added the ability to record log_entries

  • 0

Initially I created Exercises to browse. Then I added the ability to record “log_entries” against them.

This works for that

  = semantic_form_for @exercise do |exercise|
    = exercise.semantic_fields_for :log_entries do |log_entry|
      = render 'log_entries/log_entry_fields', :f => log_entry
    .links
      = link_to_add_association 'Add Set', exercise, :log_entries, :partial => "log_entries/log_entry_fields", :data => {:role => "button", :icon => "plus"}
    = exercise.buttons do
      = exercise.commit_button "Apply", :button_html => {:data => {:icon => "check", :theme => "b"}}
      = link_to "Cancel", "", :data => {:rel => "back", :icon => "delete", :role => "button", :theme => "a"}

I now added the requirement of needing it to be associated to a user. I’m not sure how to do that in the best manner. This is posting to the exercise controller now, and an exercise isn’t really associated with a user. So in the exercise controller I could merge the params in, but that seems hackish.

The proper way would be to create the log entry association through the user, right? But how would I restructure the form to make that work?

I probably shouldn’t be using the exercise controller anymore either for that since it’s creating log_entries, and then in the LogEntryController the user can be set through there… but what’s the best way to do this? For some reason I can’t figure out how to pass in the workout to the log_entries controller and then have the collection render in the form like shown.

Maybe I’m brain pooped from coding all day. Thanks!

I’m using the Cocoon library for the add association functionality.

  • 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-09T18:03:17+00:00Added an answer on June 9, 2026 at 6:03 pm

    You don’t need a gem to accomplish this. Consider the following associations:

    class User < ActiveRecord::Base
      has_many :log_entries
    end
    
    class Exercise < ActiveRecord::Base
      has_many :log_entries
    end
    
    class LogEntry < ActiveRecord::Base
      belongs_to :user
      belongs_to :exercise
    end
    

    And the following deeply-nested routes:

    YourApp::Application.routes.draw do
      resources :users do
        resources :exercises do
          resources :log_entries
        end
      end
    end
    

    Which would result in a new link looking like this (long, I know):

    <%= link_to new_user_exercise_log_entry_path(user, exercise) %>
    

    where user and exercise are the user and exercise objects that the log_entry will belong to. The resource part of your URI would look something like this, for example:

    /users/1/exercises/1/log_entries/new
    

    Note, that it’s the log_entry form that you should be submitting, not the exercise form.

    And you wouldn’t have to do anything special with your log_entry form. Since the relations exist between the models and the routes are nested, you can simply access the params[:user_id] and params[:exercise_id] in your log_entry controller action and assign them to your new log_entry object there.

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

Sidebar

Related Questions

I have a decorator chain that looks like this when initially created: IType calculator
I need to decrypt a conection that was created initially under an account that
As I've come to understand using $('.whatever').click() only works for items created initially. Additional
I initially created an SQLite database on Windows and then had problems accessing it
Currently I am working on an existing website that was initially created using SMF
I have a multidimensional array built from Strings that is initially created with the
We have few components like libraries dlls When initially created I ran the following
What objects are created initially by compilers(?) of javascript? I've been learning Io in
If a VS2008 project is created initially with a web app project, and class
I am using MVC4's WEB API to expose a controller. Initially I created created

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.