# -*- encoding : utf-8 -*- class Admin::CommentsController < ApplicationController before_filter :auth_admin layout "admin" before_filter :find_comments def index require 'csv' csv_text = File.open(Rails.root.join("comments.csv")).read.encode("utf-8") csv = CSV.parse(csv_text, :col_sep => ",") csv.each do |row| c = Comment.new(:pseudo => row[0], :comment => row[1]) if row[3].to_i == 4 c.commentable_id = 43 c.commentable_type = "MenuItem" c.enabled = true else c.commentable_id = row[3] c.enabled = false end c.save c.created_at = row[2] c.save end end def edit @comment = Comment.find(params[:id]) end def update @comment = Comment.find(params[:id]) if @comment.update_attributes(params.require(:comment).permit!) else render :action => "edit" end end def destroy @comment = Comment.find(params[:id]) @comment.destroy end def find_comments @comments = Comment.order("created_at DESC").all end end