Last active
May 12, 2021 01:19
-
-
Save IsaacGonzalez/72687e8ad9a9c491ae86e04f57dac024 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
<%= form_with(model: recomendacion) do |form| %> | |
<% if recomendacion.errors.any? %> | |
<div id="error_explanation"> | |
<h2><%= pluralize(recomendacion.errors.count, "error") %> prohibited this recomendacion from being saved:</h2> | |
<ul> | |
<% recomendacion.errors.each do |error| %> | |
<li><%= error.full_message %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<p> | |
<%= form.label :descripcion %><br> | |
<%= form.text_field :descripcion %> | |
</p> | |
<div class="actions"> | |
<%= form.submit %> | |
</div> | |
<% 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
class Recomendacion < ApplicationRecord | |
validates :descripcion, presence: true | |
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
class RecomendacionsController < ApplicationController | |
before_action :set_recomendacion, only: %i[ show edit update destroy ] | |
# GET /recomendacions or /recomendacions.json | |
def index | |
@recomendacions = Recomendacion.all | |
end | |
# GET /recomendacions/1 or /recomendacions/1.json | |
def show | |
end | |
# GET /recomendacions/new | |
def new | |
@recomendacion = Recomendacion.new | |
end | |
# GET /recomendacions/1/edit | |
def edit | |
end | |
# POST /recomendacions or /recomendacions.json | |
def create | |
@recomendacion = Recomendacion.new(recomendacion_params) | |
respond_to do |format| | |
if @recomendacion.save | |
format.html { redirect_to @recomendacion, notice: "Recomendacion was successfully created." } | |
format.json { render :show, status: :created, location: @recomendacion } | |
else | |
format.html { render :new, status: :unprocessable_entity } | |
format.json { render json: @recomendacion.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PATCH/PUT /recomendacions/1 or /recomendacions/1.json | |
def update | |
respond_to do |format| | |
if @recomendacion.update(recomendacion_params) | |
format.html { redirect_to @recomendacion, notice: "Recomendacion was successfully updated." } | |
format.json { render :show, status: :ok, location: @recomendacion } | |
else | |
format.html { render :edit, status: :unprocessable_entity } | |
format.json { render json: @recomendacion.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /recomendacions/1 or /recomendacions/1.json | |
def destroy | |
@recomendacion.destroy | |
respond_to do |format| | |
format.html { redirect_to recomendacions_url, notice: "Recomendacion was successfully destroyed." } | |
format.json { head :no_content } | |
end | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_recomendacion | |
@recomendacion = Recomendacion.find(params[:id]) | |
end | |
# Only allow a list of trusted parameters through. | |
def recomendacion_params | |
# params.fetch(:recomendacion, {}) | |
params.require(:recomendacion).permit(:descripcion) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment