Files
growstuff/app/controllers/scientific_names_controller.rb
2016-12-07 23:54:03 +00:00

92 lines
2.5 KiB
Ruby

class ScientificNamesController < ApplicationController
before_action :authenticate_member!, except: [:index, :show]
load_and_authorize_resource
# GET /scientific_names
# GET /scientific_names.json
def index
@scientific_names = ScientificName.all
respond_to do |format|
format.html # index.html.haml
format.json { render json: @scientific_names }
end
end
# GET /scientific_names/1
# GET /scientific_names/1.json
def show
respond_to do |format|
format.html # show.html.haml
format.json { render json: @scientific_name }
end
end
# GET /scientific_names/new
# GET /scientific_names/new.json
def new
@scientific_name = ScientificName.new
@crop = Crop.find_or_initialize_by(id: params[:crop_id])
respond_to do |format|
format.html # new.html.haml
format.json { render json: @scientific_name }
end
end
# GET /scientific_names/1/edit
def edit
end
# POST /scientific_names
# POST /scientific_names.json
def create
params[:scientific_name][:creator_id] = current_member.id
@scientific_name = ScientificName.new(scientific_name_params)
respond_to do |format|
if @scientific_name.save
format.html { redirect_to @scientific_name.crop, notice: 'Scientific name was successfully created.' }
format.json { render json: @scientific_name, status: :created, location: @scientific_name }
else
format.html { render action: "new" }
format.json { render json: @scientific_name.errors, status: :unprocessable_entity }
end
end
end
# PUT /scientific_names/1
# PUT /scientific_names/1.json
def update
respond_to do |format|
if @scientific_name.update(scientific_name_params)
format.html { redirect_to @scientific_name.crop, notice: 'Scientific name was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @scientific_name.errors, status: :unprocessable_entity }
end
end
end
# DELETE /scientific_names/1
# DELETE /scientific_names/1.json
def destroy
@crop = @scientific_name.crop
@scientific_name.destroy
respond_to do |format|
format.html {
redirect_to @crop, notice: 'Scientific name was successfully deleted.'
}
format.json { head :no_content }
end
end
private
def scientific_name_params
params.require(:scientific_name).permit(:crop_id, :name, :creator_id)
end
end