Created
December 21, 2014 20:23
-
-
Save ckib16/25acd8ebcf01a597ce1c to your computer and use it in GitHub Desktop.
refactored controller with topics_params method
This file contains hidden or 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
| 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