From c3865ab319341b505b34c369cc6e5e5a2625a39b Mon Sep 17 00:00:00 2001 From: yanxd Date: Sat, 7 Jun 2014 10:45:57 +0800 Subject: [PATCH] notificationcomments --- app/controllers/notificationcomments_controller.rb | 12 ++++++------ app/models/contestnotification.rb | 2 +- app/views/contestnotifications/new.html.erb | 2 +- config/routes.rb | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/notificationcomments_controller.rb b/app/controllers/notificationcomments_controller.rb index 6e4b12eb..80500ab1 100644 --- a/app/controllers/notificationcomments_controller.rb +++ b/app/controllers/notificationcomments_controller.rb @@ -8,14 +8,14 @@ class NotificationcommentsController < ApplicationController @contest = Contest.find(params[:contest_id]) @contestnotification = Contestnotification.find(params[:contestnotification_id]) - @notificaioncomment = Notificationcomment.new - @notificaioncomment.safe_attributes = params[:notificaioncomment] - @notificaioncomment.author = User.current - if @contestnotification.notificationcomments << @notificaioncomment - flash[:notice] = l(:label_comment_added) + # @notificaioncomment = Notificationcomment.new + # @notificaioncomment.safe_attributes = params[:notificationcomment] + # @notificaioncomment.author = User.current + comment = @contestnotification.notificationcomments.new(params[:notificationcomment].merge(author_id: User.current.id)) + if comment.save + flash[:notice] = l(:label_comment_added) end - #redirect_to contest_contestnotification_notificationcomment_path(@contest, @contestnotification, @notificaioncomment) redirect_to contest_contestnotification_path(@contest, @contestnotification) end diff --git a/app/models/contestnotification.rb b/app/models/contestnotification.rb index c96a61d9..0bda4954 100644 --- a/app/models/contestnotification.rb +++ b/app/models/contestnotification.rb @@ -5,7 +5,7 @@ class Contestnotification < ActiveRecord::Base #Contestnotification::Notificationcomment belongs_to :contest belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' - has_many :notificationcomments, :dependent => :delete_all, :order => "created_at" + has_many :notificationcomments, as: :notificationcommented, :dependent => :delete_all, :order => "created_at" # fq has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy diff --git a/app/views/contestnotifications/new.html.erb b/app/views/contestnotifications/new.html.erb index c4e322ec..634cf64c 100644 --- a/app/views/contestnotifications/new.html.erb +++ b/app/views/contestnotifications/new.html.erb @@ -2,6 +2,6 @@ <%= labelled_form_for @contestnotification, :url => contest_contestnotifications_path(@contest), :html => { :id => 'contestnotifications-form', :multipart => true } do |f| %> <%= render :partial => 'contestnotifications/form', :locals => { :f => f } %> <%= submit_tag l(:button_create), :class => "whiteButton m3p10 h30" %> - <%= preview_link preview_contestnotifications_path(:contest_id => @contest), 'contestnotifications-form' ,target='preview',{:class => 'whiteButton m3p10'}%> + <%= preview_link preview_contest_contestnotifications_path(:contest_id => @contest), 'contestnotifications-form' ,target='preview',{:class => 'whiteButton m3p10'}%> <% end %>
diff --git a/config/routes.rb b/config/routes.rb index 3ba384a8..3937a2e2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -77,6 +77,7 @@ RedmineApp::Application.routes.draw do ## new added by linchun #新竞赛相关 resources :contests, only: [:index] do resources :contestnotifications do + get 'preview', on: :collection resources :notificationcomments end