Created
April 22, 2014 20:04
-
-
Save kenyonj/11192449 to your computer and use it in GitHub Desktop.
Discussions_Controller
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
class DiscussionsController < ApplicationController | |
before_action :authorize, only: [:new, :create] | |
def new | |
@discussion_form = DiscussionForm.new | |
@types = ["Image", "Document", "Code", "Video", "Audio"] | |
end | |
def show | |
@discussion = Discussion.find_by(token: params[:id]) | |
@comments = @discussion.comments.recent | |
@comment = Comment.new | |
@content = @discussion.content | |
end | |
def create | |
@discussion_form = DiscussionForm.new(form_params) | |
@types = ["Image", "Document", "Code", "Video", "Audio"] | |
if @discussion_form.valid? | |
content = @discussion_form.persist | |
redirect_to content.discussion | |
else | |
render :new | |
end | |
end | |
private | |
def form_params | |
params.require(:discussion_form). | |
permit( | |
:name, | |
:type, | |
:subject | |
). | |
merge(user: current_user) | |
end | |
def discussion_params | |
params.require(:discussion).permit(:name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment