Title / Description
Code class GrowsController < ApplicationController before_filter :authenticate_user! def index @grows = current_user.grows if @grows.size < 1 flash[:notice] = "Please add a new garden before continuing." redirect_to new_grow_path end end def show @grow = Grow.where(id: params[:id]).eager_load(:notifications, :schedules).first end def new @grow = Grow.new end def update @grow=Grow.find(params[:id]) if @grow.update(grows_attr) redirect_to grow_path(@grow, anchor: "four"), notice: 'Parameters updated.' else redirect_to @grow, error: 'Error occurred while saving data.' end end def create @grow = Grow.new(grows_attr) @grow.crop = DateTime.now + params[:grow_weeks].to_i.weeks @grow.user = current_user if @grow.save flash[:notice] = "Garden saved successfully." redirect_to @grow else flash[:alert] = "Error encountered while saving." render "new" end end def destroy Grow.find(params[:id]).delete flash[:notice] = "Garden removed successfully." redirect_to grows_path end end
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code