Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to relate such as tables of a scaffold and a model and presentation of data in the show.html.erb view of the scaffold. Rails.

Thomaz Wanderbruck Schmidt asked in Rails

I am making a patient control system where I have the following tables that I need to list and present the data on the show.html.erb of patients.

I created a patient scaffold with the following data

  t.string :cpf
  t.string :name
  t.string :telephone
  t.string :rg
  t.date :birth
  t.string :mother

and a model address with the following data

t.string :street
t.integer :cep
t.string :city
t.string :state
t.string :neighborhood

the ratio is 1 to 1 (belongs to) my question is how do i do all this relation and how do i present the data from the addresses table in the patients show.html.erb.

Reply

Hey Thomaz,

You can simply access the data through the Patient association to Address.

<%= patient.address.street %>

Reply

return this error now

unknown attribute 'street' for Patient.
Extracted source (around line #27

def create
@patient = Patient.new(patient_params)

respond_to do |format|
  if @patient.save
Reply

You can't save street to the Patient model if you don't have have a column with that name.

You said you were using a separate table to store the addresses, so you would need to use a nested form to fill out Patient and Address details at the same time.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.