Skip to content

Instantly share code, notes, and snippets.

@litch
Created December 10, 2013 16:40
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save litch/7893723 to your computer and use it in GitHub Desktop.
Save litch/7893723 to your computer and use it in GitHub Desktop.
=render @memory_page.approved_comments
= simple_form_for [@memory_page, Comment.new], html: {class: 'form-inline'} do |f|
.form-inputs
.row
.col-md-12
= f.input :comment, label: "Add Your Comment", input_html: {class: 'editable'}
.row#hidden_form_elements.hide //I have some JS callback that will display these fields once the parent input has been edited
.col-md-6
= f.input :name
.col-md-6
= f.input :email
.form-actions
= f.button :submit, "Create Comment"
class CommentsController < ApplicationController
before_action :current_resource
respond_to :html
layout 'admin'
def create
@comment = @memory_page.approved_comments.build(comment_params)
@comment.user = current_user
respond_to do |format|
if @comment.save
format.html { redirect_to [@memory_page], notice: 'Thank you, your comment has been recorded.' }
format.json { render action: 'show', status: :created, location: @memory_page }
else
format.html { render action: 'new' }
format.json { render json: @picture.errors, status: :unprocessable_entity }
end
end
end
def index
@pending_comments = @memory_page.pending_comments
@approved_comments = @memory_page.approved_comments
@flagged_comments = @memory_page.flagged_comments
end
def update
@comment = Comment.find(params[:id])
@comment.update_attributes(comment_params)
respond_with @comment
end
private
def current_resource
@memory_page = MemoryPage.friendly.find(params[:memory_page_id]) if params[:memory_page_id]
end
def comment_params
params.require(:comment).permit(:title, :comment, :role, :name, :email)
end
end
class MemoryPage < ActiveRecord::Base
extend FriendlyId
resourcify
has_many :pictures
accepts_nested_attributes_for :pictures, :reject_if => :all_blank, :allow_destroy => true
acts_as_commentable :pending, :approved, :flagged
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment