Last active
December 14, 2019 18:28
-
-
Save GAierken/2f65d1d6ba662af5d847df0f4b608ef7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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