jjzjj

data-value

全部标签

c - Data_wrap_struct 和标记函数

我正在编写一个Ruby扩展,我正在使用函数Data_wrap_struct。为了参与Ruby的标记和清除垃圾收集过程,我需要定义一个例程来释放我的结构,以及一个例程来标记从我的结构到其他结构的任何引用。我通过经典的free函数来释放内存,但我不知道如何使用标记函数。我的结构听起来像这样typedefstruct{intx;inty;}A;typedefstruct{Acollection[10];intcurrent;}B;我认为我需要一个标记函数来标记结构B的collection中的引用。谁能给我看一个例子,看看标记函数是如何工作的? 最佳答案

ruby-on-rails - rails : accessing field value from model method

刚开始学习Rails(三)。我正在努力寻找如何做一些可能完全微不足道的事情:从该模型的方法内部访问模型实例字段的值。以我为例:defformal_name@title+""+@forename+""+@surnameend所有三个@properties(它们都是数据库中表上的字段)都返回nil。他们不应该。令人难以置信的是,http://guides.rails.info/并未讨论如何访问字段,google什么也找不到。顺便说一句,我来自Django,这里的东西很明显。 最佳答案 @语法用于实例变量,这些实例变量(例如)在Contr

ruby-on-rails - 在 RSpec 中获取 'Bad value for range'

这是我的代码:#app/models/user.rbclassUser:modeldolet(:user){FactoryGirl.create:user}it"shouldreturnthecorrectdisplayname"doexpect(user.display_name).toeql("Chuck")endend#spec/factories/users.rbFactoryGirl.definedofactory:userdoprovider"MyString"uid"MyString"name"ChuckNorris"oauth_token"MyString"oauth_

Ruby 相当于 perl 的 "Data::Dumper",用于打印深度嵌套的哈希/数组

这不是RubyequivalentofPerlData::Dumper的副本.这个问题已经超过3.5年了,因此想检查从那时起Ruby中是否有任何可用的新选项。我正在寻找perl的Dumper在ruby​​中的等价物。我不在乎Dumper在幕后做了什么。我已经广泛使用它在perl中打印深度嵌套的哈希和数组。到目前为止,我还没有在ruby​​中找到替代品(或者我可能没有找到一种方法来充分利用Ruby中的可用替代品)。这是我的perl代码及其输出:#!/usr/bin/perl-wusestrict;useData::Dumper;my$hash;$hash->{what}->{where}

ruby-on-rails - 事件管理员 :select drop-down defaults to current value in development but defaults to blank in production

我有以下ActiveAdmin表单:formdo|f|f.inputs"TimesheetDetails"dof.input:jobs_assigned_worker,:label=>"Worker",as::select,collection:Worker.allf.input:worked_time_hours,:label=>"WorkedTime(Hours)"f.input:worked_time_mins,:label=>"WorkedTime(Minutes)"f.input:driving_time_hours,:label=>"DrivingTime(Hours)"f

ruby-on-rails - Rails 3.1 和 Ruby 1.9.3p125 : ruby-debug19 still crashes with "Symbol not found: _ruby_threadptr_data_type"

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:ruby-debugwithRuby1.9.3?我听说ruby​​1.9.3p125有解决ruby​​-debug19问题的传言,所以根据RVM站点上的说明,我重新安装了1.9.3:$rvmreinstall1.9.3--patchdebug--force-autoconf$ruby-vruby1.9.3p125(2012-02-16revision34643)[x86_64-darwin11.2.0]然后:geminstallruby-debug19将此条目添加到我的Gemfile中:gem'ruby-de

ruby-on-rails - rails 4 : Forcing specific values with "strong parameters"

我正在努力使用用于创建“项目”的表单。最后,我只想允许当前的user_id,但我还没有构建用户模型或身份验证,因此作为占位符,我只是硬编码1。app/views/projects/new.html.erb:{:action=>'create'})do|f|%>1})%>app/controllers/projects_controller.rbdefcreate#saveobjectifProject.create(project_params)redirect_to(:action=>'show')elserender('new')endendprivatedefproject_pa

ruby-on-rails - rails/ ruby : TimeWithZone comparison inexplicably failing for equivalent values

我在当前项目中比较DateTime时遇到了一段糟糕的时光(没有双关语意),特别是比较ActiveSupport::TimeWithZone的两个实例。问题是我的两个TimeWithZone实例具有相同的值,但所有比较都表明它们不同。执行调试时暂停(使用RubyMine),可以看到如下信息:timestamp={ActiveSupport::TimeWithZone}2014-08-0110:33:36UTCstarted_at={ActiveSupport::TimeWithZone}2014-08-0110:33:36UTCtimestamp.inspect="Fri,01Aug20

ruby - `sort_by' : comparison of Array with Array failed (no nil data)

classCustomSorterattr_accessor:start_date,:availabledefinitialize(start_date,available)@start_date=Time.mktime(*start_date.split('-'))@available=availableendendcs1=CustomSorter.new('2015-08-01',2)cs2=CustomSorter.new('2015-08-02',1)cs3=CustomSorter.new('2016-01-01',1)cs4=CustomSorter.new('2015-0

ruby-on-rails - 为什么 PG::UniqueViolation: ERROR: duplicate key value violates unique constraint?

我有一个模型Post,每次创建帖子时,我都希望同时创建一个新的Moderation实例。所以在post.rb中我使用回调after_save:create_moderation然后写一个私有(private)方法:...includeReportableafter_save:create_moderationprivatedefcreate_moderationself.create_moderation!(blog:Blog.first)end但是在创建提案时出现此错误:PG::UniqueViolation:ERROR:duplicatekeyvalueviolatesunique