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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:21:50+00:00 2026-06-14T19:21:50+00:00

I have a nested model resources :customer do resources :readings end Customers model has

  • 0

I have a nested model

resources :customer do
  resources :readings
end

Customers model has

class Customer < ActiveRecord::Base
 attr_accessible :first_name, :last_name, :phase_type, :readings_attributes
 has_many :readings
end

Readings Controller has

 class Reading < ActiveRecord::Base
   attr_accessible :customer_id, :date_of_reading, :reading1, :reading2, :reading3
   belongs_to :customer
 end

I have written a helper method to determine how to render partials based on the phase_type in the customer’s model however, the helper method is rendered in a form in the readings edit view.

The form in readings/_form_reading is

<%= simple_form_for [@reading.customer, @reading], :html => { :class => 'form- horizontal' } do |f| %>
<%= render "shared/error_messages", :target => @reading %>
<%= f.input :customer_id %>
<%= f.input :date_of_reading, :as => :date %>
<%= render_readings_conditionally(f) %>
<div class="form-actions">
  <%= f.button :submit, :class => 'btn-primary' %>
  <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
              customer_path, :class => 'btn' %>
</div>
<% end %>

The Render_readings_conditionally helper is

module ApplicationHelper
def render_readings_conditionally(form)
 if @customer.phase_type == 'Single Phase'
  render 'readings/single_phase',f: form
 else
  render 'readings/three_phase',f: form
 end 
 end
end

The problem i have is i need to determine the type of customer phase type in order to render partials unconditionally however, @customer.phase_type will not work because it is not in the readings model, how can i access it?

  • 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-14T19:21:52+00:00Added an answer on June 14, 2026 at 7:21 pm

    I’m not sure what you want to do but maybe this will help in something.
    routes.rb for nested resources should be like this:

    resources :customers do
      resources :readings
    end
    

    If you want to access phase_type in @reading

    @reading.customer.phase_type
    

    Rails nested resource guide

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

Sidebar

Related Questions

I have a nested model resources: customers do resources: readings end I am trying
I have a model with nested attributes : class Foo < ActiveRecord::Base has_many :bar
Given a model like: class PhoneNumber < ActiveRecord::Base has_many :personal_phone_numbers has_many :household_phone_numbers has_many :organization_phones
I have a nested model structure that looks like this: resources :users, :path =>
I have built a nested resources between question and answer model. This is form
I have a form where the model has a nested resource (an image uploaded
I have a nested resources: resources :bills do resources :debts end and when I
I have a model, ModelRun , that accepts nested attributes for another model, ParameterValue
Is it possible for a model to belong_to, two models and have a nested
I'm using the friendly_id gem. I also have my routes nested: # config/routes.rb map.resources

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.