diff --git a/app/controllers/notificationcomments_controller.rb b/app/controllers/notificationcomments_controller.rb index 6e4b12eb8..80500ab10 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 c96a61d92..0bda49548 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 c4e322ec8..634cf64c4 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 3ba384a89..3937a2e20 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