![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
ruby
文章平均质量分 58
冰凌花花
欢迎来到我的博客, 本人乃互联网行业一枚小小的螺丝钉—非典型程序员妹子.
展开
-
Rails 上传CSV数据
def upload(file_name) csv = IO.read(file_name).split("\n") csv[1..-1].map do |x| data = x.split(',') sid = data[0].gsub(/"/, '') puts sid current_term = data[1].gsub(/"/, '').chop number_of_payments = data[2].gsub(/"/, '').cho...原创 2021-10-18 18:26:29 · 164 阅读 · 0 评论 -
each-Select
While Ruby’s each method is useful, it also comes with an awesome extended family of methods that are even more powerful!For the next few examples, we’ll work with a slightly more complex data str原创 2016-04-30 17:03:17 · 351 阅读 · 0 评论 -
map
map is another extremely useful Ruby iterator. It helps us map data from one form to another. It will return a new Array containing the result of running the specific block on each element in the coll原创 2016-04-30 17:29:13 · 216 阅读 · 0 评论 -
Encapsulation and Requiring Files
By encapsulating all the logic for an object, whether it’s a Dog or a User or an IceCreamShop, you are able to keep all of the logic and responsibilities of your object within its own scope. This lets原创 2016-05-01 15:01:40 · 242 阅读 · 0 评论 -
Public and Private Interfaces in ruby
Your latest client is a bank, and they’ve tasked you with requiring customers to enter their password in order to make withdrawals.Currently, this is what they’ve got:class Customer attr_rea原创 2016-05-02 22:09:37 · 272 阅读 · 0 评论 -
Class Methods & Variables
When calling an instance method like withdraw_securely, the syntax generally looks something like this:object.method_being_called(arguments)One would therefore think it’s safe to assume that原创 2016-05-07 21:03:22 · 530 阅读 · 0 评论 -
ruby Inheritance
Often, classes will have shared characteristics with other classes.Rewriting the same methods for each class over and over again can be pretty cumbersome, and not always necessary.class BankTe原创 2016-05-08 10:44:53 · 265 阅读 · 0 评论 -
ruby Errors & Exceptions
When you first started coding, errors were probably the last thing you wanted to see.After all, it’s not a far stretch to associate “error” with “I messed up”.Hopefully by now you’ve come to appre原创 2016-05-08 12:07:41 · 461 阅读 · 0 评论 -
ruby on rails 使用text存储hash类型的数据 Use text filed to store the hash map
在component表里用text类型的字段存储hash数据(1)新建字段 ,这是migration的内容class AddHintsToComponents ] def change add_column :components, :hints, :text end end(2)controller def update原创 2016-08-31 16:55:23 · 972 阅读 · 0 评论 -
简化查询
def search @videos = Video.where("videoid LIKE ? or title LIKE ?", "%#{params[:q]}%", "%#{params[:q]}%") render :index end 使用hash的写法 def search @videos = Video.where("videoid L原创 2016-12-12 13:09:16 · 405 阅读 · 0 评论 -
RubyOnRails local_assigns
http://api.rubyonrails.org/classes/ActionView/Template.html#method-i-local_assignsReturns a hash with the defined local variables.Given this sub template rendering:You can use local_assig原创 2016-12-21 13:17:59 · 464 阅读 · 0 评论 -
序列化.to_sym
def showable_paths{ #Filter: cibn_filterlists_path, Video: videos_path, Subject: cibn_special_subjects_path, Star: stars_path} end原创 2016-04-14 16:04:12 · 297 阅读 · 0 评论 -
invert
http://docs.ruby-lang.org/en/2.0.0/Hash.htmlinvert → new_hashReturns a new hash created by using hsh's values as keys, and the keys as values.h = { "n" => 100, "m" => 100, "y" => 300, "d" => 2原创 2016-04-25 17:42:41 · 593 阅读 · 0 评论 -
升级Rubygems
https://rubygems.org/$gem update --systemupdategem update --systemUpdate to the latest RubyGems version原创 2014-09-02 14:59:09 · 1443 阅读 · 0 评论 -
form_tag (ActionView::Helpers::FormTagHelper)
form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block)Starts a form tag that points the action to an url configured with url_for_options just like ActionController::Base#url_f原创 2014-10-22 11:44:42 · 574 阅读 · 0 评论 -
ruby系统使用memcache缓存
如何将ruby自带的文件缓存换为memcache缓存原创 2015-04-14 16:16:13 · 1246 阅读 · 0 评论 -
找不到rails console命令
部署新服务器后发现,没有rails console命令了root@i-1lb6pxls:/home/ubuntu/campo/current# bundle exec rails cUsage: rails new APP_PATH [options]Options: -r, [--ruby=PATH]原创 2015-08-25 16:54:23 · 1966 阅读 · 0 评论 -
cache目录没有操作权限
今天部署新服务器发现了cache文件夹木有权限读写App 26772 stderr: Started GET "/investors" for 103.238.226.130 at 2015-08-25 11:25:47 +0800App 26772 stderr: Processing by InvestorsController#index as HTMLApp 26772 stder原创 2015-08-25 17:07:31 · 4698 阅读 · 0 评论 -
PostgreSQL新手上路PG::ConnectionBad (FATAL: Peer authentication failed
PostgreSQL新手上路PG::ConnectionBad (FATAL: Peer authentication failed原创 2015-08-25 17:57:15 · 1798 阅读 · 0 评论 -
incompatible character encodings: UTF-8 and ASCII-8BIT
http://stackoverflow.com/questions/5286117/incompatible-character-encodings-ascii-8bit-and-utf-8http://stackoverflow.com/questions/22932282/gemloaderror-specified-mysql2-for-database-adapter-but-t原创 2015-10-21 18:26:29 · 1875 阅读 · 0 评论 -
为应用增加登录功能 ruby on rails
ruby on rails 的应用,如何增加登录注册功能,本文就演示这个全过程原创 2015-10-26 19:06:37 · 889 阅读 · 0 评论 -
安装ruby一定要注意的一步(ruby -v和 rbenv version结果不一致)
https://github.com/rbenv/rbenv#installation安装ruby的第三步Run ~/.rbenv/bin/rbenv init for shell-specific instructions on how to initialize rbenv to enable shims and autocompletion.[webuse原创 2016-03-04 13:54:33 · 3543 阅读 · 1 评论 -
select function in ruby
# TODO: 使用 MySQL 的 FIND_IN_SET,必须过滤掉逗号分割符之间的空格 # http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_find-in-set custom_subjects = SpecialSubject.where('state = ? AND pid原创 2016-04-08 14:04:41 · 246 阅读 · 0 评论 -
SecureRandom加密的强随机数生成器
(1)base64(n=nil)转载 2014-09-01 10:40:17 · 2410 阅读 · 0 评论