Skip to content

Instantly share code, notes, and snippets.

@eqbal
Created December 6, 2016 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eqbal/e908698a46ec7bc400d94b13a37b3d44 to your computer and use it in GitHub Desktop.
Save eqbal/e908698a46ec7bc400d94b13a37b3d44 to your computer and use it in GitHub Desktop.
class EntriesController < ApplicationController
before_action :authenticate_user!
def index
@entry = Entry.new
@entries = current_user.entries.order(created_at: :desc)
end
def create
@entry = Entry.new(entry_params)
@entry.user_id = current_user.id
if @entry.save
flash[:notice] = "Entry was successfully created."
else
flash[:error] = @entry.errors.full_messages.to_sentence
end
redirect_to root_path
end
def destroy
@entry = Entry.find(params[:id])
if @entry.destroy!
flash[:notice] = "Entry was destroyed."
else
flash[:error] = @entry.errors.full_messages.to_sentence
end
redirect_to root_path
end
private
def entry_params
params.require(:entry).permit(:user_id, :distance, :time_period, :date_time, :created_at, :updated_at, :distance_type, :status_weather, :status_landform)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment