Skip to content

Instantly share code, notes, and snippets.

@ckib16
Created December 21, 2014 20:23
Show Gist options
  • Save ckib16/25acd8ebcf01a597ce1c to your computer and use it in GitHub Desktop.
Save ckib16/25acd8ebcf01a597ce1c to your computer and use it in GitHub Desktop.
refactored controller with topics_params method
def create
@topic = Topic.new(topics_params)
authorize @topic
if @topic.save
redirect_to @topic, notice: "Topic was saved successfully."
else
flash[:error] = "Error creating topic. Please try again."
render :new
end
end
def update
@topic = Topic.find(params[:id])
authorize @topic
if @topic.update_attributes(topics_params)
redirect_to @topic
else
flash[:error] = "Error updating topic. Please try again."
render :edit
end
end
private
def topics_params
params.require(:topic).permit(:name, :description, :public)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment