Class: Cornerstone::DiscussionsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Cornerstone::DiscussionsController
- Defined in:
- app/controllers/cornerstone/discussions_controller.rb
Instance Method Summary collapse
-
#category ⇒ Object
GET /cornerstone/discussions/:category.
-
#create ⇒ Object
POST /cornerstone/discussions/.
-
#index ⇒ Object
GET /cornerstone/discussions/.
-
#new ⇒ Object
GET /cornerstone/discussions/new.
-
#show ⇒ Object
GET /cornerstone/discussions/:category/:id.
Instance Method Details
#category ⇒ Object
GET /cornerstone/discussions/:category
22 23 24 25 26 |
# File 'app/controllers/cornerstone/discussions_controller.rb', line 22 def category @category = Category.includes(:discussions => :posts).find(params[:category]) @discussions = @category.discussions respond_with(@discussions, :template => "cornerstone/discussions/categorical_index") end |
#create ⇒ Object
POST /cornerstone/discussions/
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/cornerstone/discussions_controller.rb', line 36 def create @discussion = Discussion.new(params[:discussion]) # assign user if signed in if current_cornerstone_user @discussion.user = current_cornerstone_user @discussion.posts.first.user = current_cornerstone_user end respond_with(@discussion.category, @discussion) do |format| if @discussion.save flash[:notice] = 'Discussion was successfully created.' format.html {redirect_to category_discussion_path(@discussion.category, @discussion)} else @categories = Category.discussions format.html {render :new} end end end |
#index ⇒ Object
GET /cornerstone/discussions/
7 8 9 |
# File 'app/controllers/cornerstone/discussions_controller.rb', line 7 def index @categories = Category.discussions end |
#new ⇒ Object
GET /cornerstone/discussions/new
12 13 14 15 16 17 18 19 |
# File 'app/controllers/cornerstone/discussions_controller.rb', line 12 def new @categories = Category.discussions @category = Category.find(params[:cat]) if params[:cat] @discussion = Discussion.new @discussion.category_id = @category.id if @category @discussion.posts.build respond_with(@discussion) end |
#show ⇒ Object
GET /cornerstone/discussions/:category/:id
29 30 31 32 33 |
# File 'app/controllers/cornerstone/discussions_controller.rb', line 29 def show @discussion = Discussion.includes(:posts => :user).find(params[:id]) @new_post = Post.new @posts = @discussion.posts end |