agenda-libre-ruby/app/controllers/notes_controller.rb

49 lines
1.4 KiB
Ruby
Raw Normal View History

2014-06-23 23:39:42 +02:00
class NotesController < ApplicationController
before_action :set_event, only: [:new, :create]
before_filter :set_mailer_host, only: [:create]
# GET /moderations/id/new
def new
@note = @moderation.notes.new
end
def create
2014-06-23 23:39:42 +02:00
@note = @moderation.notes.new(note_params)
@note.author = current_user
respond_to do |format|
if @note.save
2014-07-01 15:50:39 +02:00
if params[:envoiParMail] == 'oui'
2014-06-23 23:39:42 +02:00
# Send an update mail to its author
NoteMailer.create(@note).deliver
@note.contents = t '.sendByMailWrap', contents: @note.contents
2014-07-01 15:50:39 +02:00
@note.save
2014-06-23 23:39:42 +02:00
end
format.html { redirect_to moderations_url, notice: t('.ok') }
format.json { render action: 'show', status: :created, location: @event }
else
format.html { render action: 'new' }
format.json { render json: @note.errors, status: :unprocessable_entity }
end
end
end
2014-02-18 09:28:04 +01:00
private
2014-06-23 23:39:42 +02:00
# Use callbacks to share common setup or constraints between actions.
def set_event
@event = Event.find params[:moderation_id]
@moderation = @event
end
# Never trust parameters from the scary internet, only allow the white list through.
def note_params
params.require(:note).permit :contents
2014-02-18 09:28:04 +01:00
end
2014-06-23 23:39:42 +02:00
# Useful to manage absolute url in mails
def set_mailer_host
ActionMailer::Base.default_url_options[:host] = request.host_with_port
2014-02-18 09:28:04 +01:00
end
end