Skip to content

Instantly share code, notes, and snippets.

@bnorberg
Last active June 13, 2016 04:35
Show Gist options
  • Save bnorberg/c343cfdadac1878a672f28f9f2e81a5f to your computer and use it in GitHub Desktop.
Save bnorberg/c343cfdadac1878a672f28f9f2e81a5f to your computer and use it in GitHub Desktop.
class TopicsController < ApplicationController
def index
@topics = Topic.all
end
# GET /topics/1
# GET /topics/1.json
def show
@topic = Topic.find(params[:id])
end
# GET /topics/new
def new
@topic = Topic.new
end
# POST /topics
# POST /topics.json
def create
@topic = Topic.new(topic_params)
respond_to do |format|
if @topic.save
format.html { redirect_to @topic, notice: 'Topic was successfully created.' }
format.json { render :show, status: :created, location: @topic }
else
format.html { render :new }
format.json { render json: @topic.errors, status: :unprocessable_entity }
end
end
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def topic_params
params.require(:topic).permit(:title, :description)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment