2014-10-02 06:00:35 +00:00
|
|
|
|
class AsksController < ApplicationController
|
|
|
|
|
def initialize
|
|
|
|
|
super
|
|
|
|
|
@app_title = 'ask'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
module_app = ModuleApp.where(:key => "ask").first
|
|
|
|
|
categories = module_app.categories
|
2014-10-23 07:03:21 +00:00
|
|
|
|
tags = module_app.tags
|
2014-10-02 06:00:35 +00:00
|
|
|
|
ask_question = AskQuestion.new
|
|
|
|
|
{
|
|
|
|
|
"ask_question" => ask_question,
|
|
|
|
|
"categories" => categories,
|
2014-10-23 07:03:21 +00:00
|
|
|
|
"tags" => tags,
|
2014-10-02 06:00:35 +00:00
|
|
|
|
"module_app" => module_app
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
@ask_question = AskQuestion.new(create_params)
|
|
|
|
|
if gotcha_valid? && @ask_question.save
|
|
|
|
|
build_email(@ask_question)
|
|
|
|
|
redirect_to "#{params[:referer_url]}/?method=thank"
|
|
|
|
|
else
|
|
|
|
|
redirect_to "#{params[:referer_url]}/?method=sorry"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def thank
|
|
|
|
|
acknowledgement = AskAcknowledgement.last
|
|
|
|
|
{
|
|
|
|
|
"acknowledgement" => acknowledgement
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def sorry
|
|
|
|
|
{}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def build_email(email_er)
|
|
|
|
|
email = Email.new
|
|
|
|
|
email.save
|
|
|
|
|
email_er.email_id = email.id
|
|
|
|
|
email_er.save
|
|
|
|
|
|
|
|
|
|
@group_mail = email_er.email_address
|
|
|
|
|
@mail_sentdate = DateTime.now
|
|
|
|
|
|
|
|
|
|
email_er.email.update_attributes(
|
|
|
|
|
:create_user=>current_user,
|
|
|
|
|
:mail_sentdate=>@mail_sentdate,
|
|
|
|
|
:module_app=>@module_app,
|
|
|
|
|
:mail_to=>@group_mail,
|
2016-11-07 02:08:04 +00:00
|
|
|
|
:mail_subject=>Site.first.title_translations["zh_tw"]+" #{t('ask.new_question')}:",
|
2014-10-02 06:00:35 +00:00
|
|
|
|
:template=>'asks/email',
|
|
|
|
|
:template_data=>{
|
2016-11-07 02:08:04 +00:00
|
|
|
|
# "title" => email_er.title,
|
2014-10-02 06:00:35 +00:00
|
|
|
|
"name" => email_er.name,
|
|
|
|
|
"identity" => email_er[:identity],
|
|
|
|
|
"mail" => email_er.mail,
|
|
|
|
|
"phone" => email_er.phone,
|
2016-11-07 02:08:04 +00:00
|
|
|
|
# "fax" => email_er.fax,
|
|
|
|
|
# "content" => email_er.content
|
|
|
|
|
"appointment" => email_er.appointment
|
2014-10-02 06:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
OrbitMailer.set_mail(email_er.email).deliver
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create_params
|
|
|
|
|
params.require(:ask_question).permit!
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|