代码审查后代码简化

hjq_beidou
huang 9 years ago
parent 909d40b4eb
commit d1e11d4260

@ -443,12 +443,7 @@ class UsersController < ApplicationController
# 资源分享请求弹框
def apply_resource
if User.current.logged?
@attachment = Attachment.find params[:attachment_id]
@state = 2
else
@state = 1
end
@attachment = Attachment.find params[:attachment_id]
respond_to do |format|
format.js
end

@ -70,7 +70,6 @@ module ApplicationHelper
attach = Attachment.find(attachment_id)
# 条件取否result结果为true则不能下载
result = attach.is_public == 0 && attach.author != User.current && !attach.get_apply_resource_status(attach.id, User.current.id) && !attach_show_allow(attach)
return result
end
# Time 2015-03-24 15:27:29

@ -143,7 +143,7 @@ class Attachment < ActiveRecord::Base
def get_apply_resource_status attachment_id, author_id
status = ApplyResource.where("attachment_id =? and user_id =?", attachment_id, author_id).first.try(:status)
status == 2 ? true :false
status == 2
end
# add by nwb

@ -1,6 +1,6 @@
<% if @state == 1 %>
<% if !User.current.logged? %>
alert("您还未登录");
<% elsif @state == 2 %>
<% else %>
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/apply_resource', :locals => {:attachment => @attachment}) %>');
showModal('ajax-modal', '500px');
$('#ajax-modal').siblings().remove();

Loading…
Cancel
Save