Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

留言功能 #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions app/controllers/ind_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def index

def show
@user = User.find(params[:id])
if @user!=current_user
@message=Message.new
@message.user = @user
end
end


Expand All @@ -30,7 +34,7 @@ def edit

def update
@user = User.find(params[:id])
if params[:ind_user][:old_password] &&current_user.valid_password?(params[:ind_user][:old_password])
if params[:ind_user][:old_password] &&!current_user.valid_password?(params[:ind_user][:old_password])
flash[:error]="请正确输入旧密码"
redirect_to :back
else
Expand Down Expand Up @@ -65,7 +69,25 @@ def bookmarked_companies
def bookmarked_jobs
@job_posts = current_user.bookmarked("JobPost")
end


def messages_users
@message = Message.new(params[:message])
if [email protected]? && @message.user!=current_user # message.user must not be nil or current_url
@message.sender=current_user
if @message.save
else
end
mail=Notifier.to_message(@message)
mail.deliver
@result={:url=>ind_user_path(current_user.id),:result=>true,:info=>"留言已经发送!"}
if current_user.is_a? OrgUser
#@url=org_user_path(current_user.id)
end
respond_to do |format|
format.json { render :json => @result }
end
end
end

def job_posts
@user = User.find(params[:id])
Expand Down
11 changes: 11 additions & 0 deletions app/mailers/notifier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Notifier < ActionMailer::Base
default :from=>ActionMailer::Base.smtp_settings[:user_name],
:return_path =>ActionMailer::Base.smtp_settings[:user_name]

def to_message(message)
mail(:to => message.user.email,:subject=>"#{message.title}" ) do |format|
format.text { render :text => message.content }
#format.html { render :text => message.content }
end
end
end
11 changes: 11 additions & 0 deletions app/models/message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# encoding: UTF-8
class Message
include Mongoid::Document
include Mongoid::Timestamps

field :title , type: String
field :content ,type: String
belongs_to :user #message receiver
belongs_to :sender, :class_name => "User",:foreign_key => "sender_id"

end
44 changes: 42 additions & 2 deletions app/views/ind_users/_side_nav_public.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,51 @@
%h5="#{@user.profile.age}岁, #{@user.profile.gender}"
%h5="#{@user.profile.residence}, #{@user.profile.nationality}国籍"
=link_to "关注","" ,:class=>'btn' unless @user==current_user
=link_to "留言","",:class=>'btn' unless @user==current_user
=link_to "留言","###",:id=>'message',:class=>'btn',"data-backdrop"=>"true",:"data-controls-modal"=>'messageModal' unless @user==current_user

%h4 中文简历
=link_to "下载", @user.chinese_resume.to_s

%h4 英文简历
=link_to "下载", @user.english_resume.to_s


- unless @user==current_user
%div{:id=>"messageModal",:class=>"modal hide fade in"}
= form_for @message,:url=>{:action=>"messages_users"},:remote => true,:"data-type"=>"json" do |f|
.modal-header
%a{:class=>"close",:href=>"###"}="x"
%h3{:style=>"background-color:#ffffff;"}="给#{@user.profile.name}留言"
.modal-body{:style=>"height:300px;"}
%fieldset
= f.hidden_field :user_id
.row
.span2= f.label :title,"标题*"
.span6= f.text_field :title,:placeholder=> "请填写标题",:required=>"required"
.row
.span2= f.label :content,"留言内容*"
.span6= f.text_area :content,:rows=>"12",:placeholder=> "请填写内容",:required=>"required"
.modal-footer
.row
%div{:id=>"messageResult",:class=>"span6"}= ""
.pull-right
= submit_tag "发送",:class=>"btn primary"
=link_to "取消","#",:class=>"btn secondary",:onclick=>"closeMessageModal();return false;"
:javascript
function closeMessageModal(){
$("#messageModal").modal("hide");
$("#messageResult").html("");
}
$(document).ready(function(){
$("#messageModal form").bind("ajax:beforeSend",function(){
$("#messageResult").html("正在发送,请稍后!");
}).bind("ajax:success",function(event,data, status, xhr){
$("#messageResult").html(data.info);
if(data.result){
document.location.href=data.url;
}else{

}
}).bind("",function(event,xhr, status, error){
$("#messageResult").html("发送错误,请重试!");
});
});
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
match 'bookmarked/org/users'=>'org_users#bookmarked_users', :as=>"bookmarked_users_for_companies"
match 'bookmarked/companies'=>'ind_users#bookmarked_companies', :as=>"bookmarked_companies"
match 'bookmarked/jobs'=>'ind_users#bookmarked_jobs', :as=>"bookmarked_jobs"


match 'messages/users'=>'ind_users#messages_users', :as=>'messages_users'

match 'org_users/:id/new/:info'=>'org_users#new',:as=>'org_user_new'
match 'org_users/:id/edit/:info'=>'org_users#edit',:as=>'org_user_edit'
Expand Down