Skip to content

Instantly share code, notes, and snippets.

@GAierken
Last active December 14, 2019 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GAierken/2f65d1d6ba662af5d847df0f4b608ef7 to your computer and use it in GitHub Desktop.
Save GAierken/2f65d1d6ba662af5d847df0f4b608ef7 to your computer and use it in GitHub Desktop.
class SlangsController < ApplicationController
before_action :require_login
skip_before_action :require_login, only: [:index, :search, :show]
def index
@slangs = Slang.all
end
def new
@slang = Slang.new
3.times{@slang.definitions.build}
end
def create
all_params = slang_params
all_params[:user] = User.find(session[:user_id])
@slang = Slang.create(all_params)
if @slang.save
redirect_to slang_path(@slang)
else
flash[:errors]=@slang.errors.full_messages
render :new
end
end
private
def slang_params
params.require(:slang).permit(:phrase, :origin, definitions_attributes: [:id, :meaning, :language, :_destroy])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment