73 lines
1.7 KiB
Ruby
73 lines
1.7 KiB
Ruby
|
class AsksController < ApplicationController
|
|||
|
def initialize
|
|||
|
super
|
|||
|
@app_title = 'ask'
|
|||
|
end
|
|||
|
|
|||
|
def index
|
|||
|
module_app = ModuleApp.where(:key => "ask").first
|
|||
|
categories = module_app.categories
|
|||
|
ask_question = AskQuestion.new
|
|||
|
{
|
|||
|
"ask_question" => ask_question,
|
|||
|
"categories" => categories,
|
|||
|
"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,
|
|||
|
:mail_subject=>Site.first.title_translations["zh_tw"]+" #{t('ask.new_question')}:"+email_er.title,
|
|||
|
:template=>'asks/email',
|
|||
|
:template_data=>{
|
|||
|
"title" => email_er.title,
|
|||
|
"name" => email_er.name,
|
|||
|
"identity" => email_er[:identity],
|
|||
|
"mail" => email_er.mail,
|
|||
|
"phone" => email_er.phone,
|
|||
|
"fax" => email_er.fax,
|
|||
|
"content" => email_er.content
|
|||
|
}
|
|||
|
)
|
|||
|
|
|||
|
OrbitMailer.set_mail(email_er.email).deliver
|
|||
|
end
|
|||
|
|
|||
|
def create_params
|
|||
|
params.require(:ask_question).permit!
|
|||
|
end
|
|||
|
|
|||
|
end
|