我不知道它是显而易见的还是我的所作所为:
控制器中的get_counter方法
def get_counter
id = params[:id]
login = id.split('@',2).first
cust_split = id.split('@',2).last
cust = cust_split.split('.',2).first
if login
id_address = ('ovm:b:'+cust+'/'+login)
else
id_address = ('ovm:b:'+cust)
end
raw_counter = (REDIS.hget(id_address, 'c'))
raw_counter_reset = (REDIS.hget(id_address, 'overquota_reset_c'))
raw_counter_reset_date = (REDIS.hget(id_address, 'overquota_reset_at'))
if raw_counter == nil
respond_to do |format|
flash[:alert] = 'Error : wrong syntax or not present in the database'
format.html { redirect_to action: 'index' }
end
else
raw_counter_int = raw_counter.to_i
bitwise_and_max = raw_counter_int & $mask_max
decal_max = bitwise_and_max >> 53
counter_max = 1024*(decal_max+1)
@counter_max = counter_max
counter_msg = raw_counter_int & $mask_msg
@counter_msg = counter_msg
if raw_counter_reset == '1'
@counter_reset = 'oui'
else
@counter_reset = 'non'
end
@counter_reset_date = Time.at(raw_counter_reset_date.to_i)
end
end
现在我尝试将这部分分开:
id = params[:id]
login = id.split('@',2).first
cust_split = id.split('@',2).last
cust = cust_split.split('.',2).first
if login
id_address = ('ovm:b:'+cust+'/'+login)
else
id_address = ('ovm:b:'+cust)
end
raw_counter = (REDIS.hget(id_address, 'c'))
raw_counter_reset = (REDIS.hget(id_address, 'overquota_reset_c'))
raw_counter_reset_date = (REDIS.hget(id_address, 'overquota_reset_at'))
raw_counter_int = raw_counter.to_i
bitwise_and_max = raw_counter_int & $mask_max
decal_max = bitwise_and_max >> 53
counter_max = 1024*(decal_max+1)
@counter_max = counter_max
counter_msg = raw_counter_int & $mask_msg
@counter_msg = counter_msg
if raw_counter_reset == '1'
@counter_reset = 'oui'
else
@counter_reset = 'non'
end
@counter_reset_date = Time.at(raw_counter_reset_date.to_i)
谁留在方法get_counter。这一部分:
if raw_counter == nil
respond_to do |format|
flash[:alert] = 'Error : wrong syntax or not present in the database'
format.html { redirect_to action: 'index' }
end
else
get_counter
end
进入控制器的方法展示。 事实上我尝试在show方法中分离重定向,因为get_counter也可以用来编辑方法。