Rails 4 default scaffold
class PenisController < ApplicationController
before_action :set_peni, only: [:show, :edit, :update, :destroy]
# GET /penis
# GET /penis.json
def index
@penis = Peni.all
end
# GET /penis/1
# GET /penis/1.json
def show
end
# GET /penis/new
def new
@peni = Peni.new
end
# GET /penis/1/edit
def edit
end
# POST /penis
# POST /penis.json
def create
@peni = Peni.new(peni_params)
respond_to do |format|
if @peni.save
format.html { redirect_to @peni, notice: 'Peni was successfully created.' }
format.json { render action: 'show', status: :created, location: @peni }
else
format.html { render action: 'new' }
format.json { render json: @peni.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /penis/1
# PATCH/PUT /penis/1.json
def update
respond_to do |format|
if @peni.update(peni_params)
format.html { redirect_to @peni, notice: 'Peni was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @peni.errors, status: :unprocessable_entity }
end
end
end
# DELETE /penis/1
# DELETE /penis/1.json
def destroy
@peni.destroy
respond_to do |format|
format.html { redirect_to penis_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_peni
@peni = Peni.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def peni_params
params.require(:peni).permit(:name, :size)
end
end
<%= form_for(@peni) do |f| %>
<% if @peni.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@peni.errors.count, "error") %> prohibited this peni from being saved:</h2>
<ul>
<% @peni.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :size %><br>
<%= f.text_field :size %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>