Thomaz Wanderbruck Schmidt

Joined

180 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in Why this error ? how I fix this.

No, I doesn't know this.

Posted in Why this error ? how I fix this.

Yes here.

Model Patient:

class Patient < ApplicationRecord
    has_one :address

    accepts_nested_attributes_for :address
end

MIgration Patient:

class CreatePatients < ActiveRecord::Migration[5.2]
  def change
    create_table :patients do |t|
      t.string :name
      t.string :cpf
      t.string :rg
      t.string :phone
      t.string :birth
      t.string :mother

      t.timestamps
    end
  end
end

My Search Controller

class Backend::SearchController < ApplicationController

  def patients
    @patients = Patient.where(cpf: params[:q])
  end

end

Need more information ? Helpme pleaase hahahaha xD

Posted in Why this error ? how I fix this.

I have a form that has fields from two different tables, the Patients table and the Addresses table. Please make a search field to use only one patient (Patient) and return his data, up to the fields in the patient table and return the right data when adding a field to present a street in case of a street and it will be the following error:

NoMethodError in Backend::Search#patients

Showing /home/thomazws/Documentos/Rails/projetohroV2/app/views/backend/search/patients.html.erb where line #106 raised:

undefined method `street' for nil:NilClass

Extracted source (around line #106):

<p>
<strong>Rua:</strong>
<%= patient.address.street %>
</p>

I have a controller for Search with this code:

class Backend::SearchController < ApplicationController

  def patients
    @patients = Patient.where(cpf: params[:q])
  end

end

and my view:

  <% @patients.each do |patient| %>

                     <p>
                        <strong>Nome:</strong>
                        <%= patient.name %>
                    </p>


                      <p>
                        <strong>CPF:</strong>
                        <%= patient.cpf %>
                    </p>

                      <p>
                        <strong>RG:</strong>
                        <%= patient.rg %>
                    </p>

                      <p>
                        <strong>Telefone:</strong>
                        <%= patient.phone %>
                    </p>

                      <p>
                        <strong>Data de Nascimento:</strong>
                        <%= patient.birth %>
                    </p>

                      <p>
                        <strong>Nome da Mãe:</strong>
                        <%= patient.mother %>
                    </p>

                      <p>
                        <strong>Rua:</strong>
                        <%= patient.address.street %>
                    </p>
                <%end%>

I'm starting a project with rails 5 and the first thing I did was add the bootstrap to rails 5. I added the gem and imported it into application.scss. I generated a devise Admin and the bootstrap worked, but then I generated a controller with the following command Rails generate backend / dashboard index. On this backend dashboard my bootstrap is not working.

here my application.scss

/
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib / assets / stylesheets, or any plugin's
 * vendor / assets / stylesheets directory can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any other CSS / SCSS
 * files in this directory. Styles in this file should be added after the last require_ * statement.
 * It is generally better to create a new file per style scope.
 *
 * /

// Custom bootstrap variables must be set or imported * before * bootstrap.
@import "bootstrap";

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

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.

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.