首页 > 其他 > 详细

12月13日help_method,session, find_by.的理解

时间:2017-12-13 13:46:59      阅读:202      评论:0      收藏:0      [点我收藏+]
helper_method

    Declare a controller method as a helper. For example,

helper_method :link_to

def link_to(name, options) … end

makes the link_to controller method available in the view.

课程遇到的如current_cart,current_user. 声明后,就可以在view里面使用这个method了。

 

find_by,find_by_id,session[]

find_by: 属于ActiveRecord提供的finder methods 之一。通过传递argument来在database中查找。

       The find_by method finds the first record matching some conditions.

find_by!: 和find_by一样,但nill的话,会报错!ActiveRecord::RecordNoFound 

find_by_id: find_by_id(params[:id]) ,估计这个用法不再使用了。

 

session[]:http://guides.rubyonrails.org/action_controller_overview.html 

简单说:就是储存的一小块数据,再controller和view中使用。 guide中篇幅很长,估计至少看30分钟。

 


http://guides.rubyonrails.org/active_record_querying.html   有22以上中finder methods可用。

(Finder methods that return a collection,such as where and group, return an instance of ActiveRecord::Relation. Methods that find a single entity实体,such as find and first, return a single instance of the model) 


 

12月13日help_method,session, find_by.的理解

原文:http://www.cnblogs.com/chentianwei/p/8031913.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!