New Discussion

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.

3
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.

Hey Thomaz,

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

<%= patient.address.street %>

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

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.

Join the discussion
Create an account Log in

Learning Ruby on Rails? Join our newsletter.

We won't send you spam. Unsubscribe at any time.