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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:05:42+00:00 2026-06-14T10:05:42+00:00

Really racking my brain on this one. I’m relatively new to Rails and trying

  • 0

Really racking my brain on this one. I’m relatively new to Rails and trying to do something that I’m sure is not too difficult.

I have a model “Trip” which has many “Days” which has many “Activities”

I am in the show.html.erb view of “Trip” and in this view, I am rendering a partial for a form that should allow me to create a new “Activity” to be associated with a “Day” or edit an existing “Activity” which already belongs to a “Day”

How do I pass to the form_for in the form partial, the local variable of which “Day” I want to create the new “Activity” for. And using that same form partial, how can I retrieve the “Day” that the “Activity” is associated with? Eventually these will be AJAX loaded objects.
I’ve googled for the past several hours and can’t find any examples similar to this. I really appreciate the help.

routes.rb

  resources :trips do
    resources :days    
  end

  resources :days do
    resources :activities
  end 

show.html.erb for the Trip

<div id="activities_list">
  <%= render :partial => "activities" %>
</div> 

<div id="activity_form">
  <%= render :partial => "/activities/form", :locals => { :activity => @activity}  %>
</div>

<div id="bottom">
<%= link_to 'Edit', edit_trip_path(@trip) %> |
<%= link_to 'Back', trips_path %>
</div>

_activities.html.erb partial

<h1><%= @trip.title %></h1>

<% @trip.days.each do |day| %>
<div id="blech_<%= day.id %>">
  <b><%= day.summary %></b>
      <% day.activities.each do |activity| %>
            <li id="activity_<%= activity.id %>"><%= link_to activity.address, edit_day_activity_path(day, activity), :remote => true  %></li>
      <% end %>
    <% end %>
  <%= link_to 'New Activity', new_day_activity_path(day), :remote => true %>
</div>
<% end %>

_form.html.erb partial I know that I need to be calling the day_activity_path with (@day,@activity) variables. but I don’t know how to get the @day variable in here

  <%= form_for([@activity], :remote => true) do |f| %>
     <fieldset>
       <%= f.label :title, "Activity" %><br />
       <%= f.text_field :title, :rows => 1 %><br />
     </fieldset>

    <div class="actions">
      <%= f.submit %>
    </div>
  <% end %>
  • 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-14T10:05:43+00:00Added an answer on June 14, 2026 at 10:05 am

    This is what I ended up doing and it works.

    In my show.html.erb for my “Trip”.

    show.html.erb

    <div id="activity_form">
    <h2>Activities</h2>
    </div> 
    

    link to “Edit’ an Activity. Notice the :remote => true which tells the Rails controller that this will be an AJAX request so to render edit.js.erb

    <%= link_to activity.location[0, 20], edit_day_activity_path(day, activity), :class=>"btn btn-info fixedwidthbtn", method: :get, :remote => true 
    

    _form.html.erb This form partial is under the Activities View directory (../views/activities/_form.html.erb).

    <%= form_for([@day, @activity], :remote => true) do |f| %>
    <fieldset>
      <%= f.label :title, "Activity" %>
      <%= f.text_field :title, :rows => 1 %> 
    </fieldset>
      <div class="actions">
        <%= f.submit %>
      </div>
    </form>
       <%= link_to 'Delete', [@day, @activity], method: :delete, data: { confirm: 'Are you sure?' } %>
    <% end %>
    

    edit.js.erb This is a file under the Activities view directory (../views/activities/edit.js.erb). Says to grab the DOM element with ID of “activity_form” and render the partial “form”

    $("#activity_form").html("<%= escape_javascript(render(:partial => "form"))%>");
    

    update.js.erb I included this javascript after hitting update on the Edit form to render an updated partial of the Activities List. So that I don’t have to reload the page to see an update.

    $("#activities_list").html("<%= escape_javascript( render(:partial => "/trips/activities") ) %>");
    

    routes.rb This is how I nest my routes. Only doing it 1 level following best practices.

    resources :trips do
    resources :days
    end

    resources :days do
    resources :activities
    end

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

Sidebar

Related Questions

This is really racking my brain, but maybe I'm trying to hard. I'm passing
Really racking my brain, I've been looking into this for 2+ days. Goal? Click/select
I've been raking my brain trying to figure this one out. I have a
Really ripping my hair out on this one. I have a JAAS Authentication Provider
Really got stuck on this simple regex. Need it to validate a string, that
I've been racking my brain trying to get my softphone to dial numbers on
Really new to kinect. I am trying to read up material I find. I
I'm new to flash and it's really bugging me that I cannot find out
I have been racking my small brain for ages now, so can this be
I really don't know what's going on here, I've been racking my brain for

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.