现在的位置: 首页 > 综合 > 正文

Ruby之 model.new_record? – parsent?

2018年09月09日 ⁄ 综合 ⁄ 共 438字 ⁄ 字号 评论关闭

判读对象是否保存/存有数据 http://api.rubyonrails.org/

@model.new_record?

判读对象是否为空 parsent?

2.0.0p247 :001 > 'a'.present?
 => true 
2.0.0p247 :002 > 1.present?
 => true 
2.0.0p247 :003 > nil.present?
 => false 
2.0.0p247 :004 > 

玩转 Controller

  before_filter :authenticate_user!, 
                :except => [:show, :questions, :users_rank]
  before_filter :pre_load
  
  layout Proc.new { |controller|
    case controller.action_name
    when 'show', 'users_rank', 'questions', 'notes', 'chs'
      return 'course_show'
    else
      return 'application'
    end
  }

抱歉!评论已关闭.