Created
March 13, 2017 16:43
-
-
Save Dysp/72f43615b441b3bca097f091cf068492 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IllnessesController < ApplicationController | |
before_action :set_illness, only: [:show, :edit, :update, :destroy] | |
# GET /illnesses | |
def index | |
@illnesses = Illness.all | |
end | |
# GET /illness/1 | |
def show | |
end | |
# GET /illness/new | |
def new | |
@illness = Illness.new | |
end | |
# GET /illness/1/edit | |
def edit | |
end | |
# POST /illness | |
def create | |
@illness = Illness.new(illness_params) | |
respond_to do |format| | |
if @illness.save | |
format.html { redirect_to @illness, notice: 'Illness was successfully created.' } | |
format.json { render :show, status: :created, location: @illness } | |
else | |
format.html { render :new } | |
format.json { render json: @illness.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PATCH/PUT /illness/1 | |
def update | |
respond_to do |format| | |
if @illness.update(illness_params) | |
format.html { redirect_to @illness, notice: 'Illness was successfully updated.' } | |
format.json { render :show, status: :ok, location: @illness } | |
else | |
format.html { render :edit } | |
format.json { render json: @illness.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /illness/1 | |
def destroy | |
@illness.destroy | |
respond_to do |format| | |
format.html { redirect_to illnesses_url, notice: 'Illness was successfully destroyed.' } | |
format.json { head :no_content } | |
end | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_illness | |
@illness = Illness.find(params[:id]) | |
end | |
# Never trust parameters from the scary internet, only allow the white list through. | |
def illness_params | |
params.require(:illness).permit(:name, :etiology, :patogenesis, :incidence, :prevalence, :category, :anamnesis, | |
clinical_attributes: [:id, :inspection, :_destroy]) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= simple_form_for(illness) do |f| %> | |
<% if illness.errors.any? %> | |
<div id="error_explanation"> | |
<h2><%= pluralize(illness.errors.count, "error") %> prohibited this illness from being saved:</h2> | |
<ul> | |
<% illness.errors.full_messages.each do |message| %> | |
<li><%= message %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<%= f.input :name %> | |
<%= f.input :etiology %> | |
<%= f.input :patogenesis %> | |
<%= f.input :incidence %> | |
<%= f.input :prevalence %> | |
<%= f.input :category %> | |
<%= f.simple_fields_for :clinical do |clinic| %> | |
<%= clinic.input :inspection %> | |
<% end %> | |
<div class="actions"> | |
<%= f.submit %> | |
</div> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment