我正在编写一个范围,应该说选择call_status = open且unit_id不是nil的所有调用.我对Ruby非常弱,也是Rails的新手,我很难表达这一点.
在这里我有:
scope :open_calls, where(:call_status => "open", :unit_id != nil).order("id ASC")
Run Code Online (Sandbox Code Playgroud)
我应该使用不同的运算符来评估nil吗?
当我在Rails中使用link_to标记时,我正试图找出在后台播放wav文件的最佳方法(类似HTML5).
这是我的一个观点的示例link_to:
<%= link_to 'At Station', at_station_mdt_index_path, :class => 'btn btn-success btn-medium', :method => :put, :remote => true %>
Run Code Online (Sandbox Code Playgroud)
我想弄清楚当按下按钮时如何使用audio_tag来触发声音.我尝试在link_to ERB中组合audio_tag,但得到各种语法错误.
任何例子都将非常感谢.
更新时间01/04/14-10:18am CT:声音一次正确发射.但是,由于将link添加到link_to链接不再触发rails路径来更改对象,因此只播放声音
查看代码:
<%= link_to 'En Route', en_route_mdt_index_path(:call_id => call.id), :class => 'btn btn-warning btn-medium', :method => :put, :remote => true, :id => "er" %>
<%= link_to 'On Scene', on_scene_mdt_index_path(:call_id => call.id), :id => 'to', :class => 'btn btn-primary btn-medium', :method => :put, :remote => true, :id => "os" %>
<%= link_to 'To Hospital', to_hospital_mdt_index_path(:call_id => call.id), :class …Run Code Online (Sandbox Code Playgroud) 我有一个Rails 3.2.18应用程序,在我的表单中我有一个年龄(int)和出生日期(datetime)的字段.我将使用一个简单的jQuery日期选择器来选择DOB.
这就是我想要发生的事情.
第一个字段是DOB(出生日期).我想选择它,并且一旦它被选中,我想计算年龄并根据该选择自动填充年龄字段.
我想我可以通过在模型上创建一个计算年龄的方法来实现它,但我不确定如何在年龄字段中填充它.也许是一些Javascript或什么?
任何帮助将不胜感激.
下面是我为另一个应用程序编写的方法,该方法根据DOB计算年龄并可以在视图中使用:
def age(dob)
now = Time.zone.now.to_date
now.year - patient_dob.year - ((now.month > patient_dob.month || (now.month == patient_dob.month && now.day >= patient_dob.day)) ? 0 : 1)
end
Run Code Online (Sandbox Code Playgroud) 我有一个Rails 3.2.14应用程序,可以在生产服务器上部署和运行.我正在努力将它部署到另一台服务器上,以便在我推出生产之前测试更改.我正在运行最新版本的passenger/nginx并使用Capistrano 2.12.0和Ruby 1.9.3-p194,因为这是一个遗留应用程序,我正试图模仿环境.
我可以毫无问题地部署应用程序,但它不会产生乘客并启动应用程序.
这是我在/var/log/nginx/error.log中遇到的错误之一
[ 2014-08-10 07:09:08.7782 733/7f2626fb2700 Pool2/Implementation.cpp:284 ]: Could not spawn process for application /home/d
eploy/exigencad/current: An error occured while starting up the preloader.
Error ID: aa5360f9
Error details saved to: /tmp/passenger-error-0aEhJZ.html
Message from application: cannot load such file -- bundler/setup (LoadError)
/home/deploy/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/home/deploy/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:263:in `block in run_load_path_setup_code'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:366:in `running_bundler'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:261:in `run_load_path_setup_code'
/usr/share/passenger/helper-scripts/rack-preloader.rb:100:in `preload_app'
/usr/share/passenger/helper-scripts/rack-preloader.rb:158:in `<module:App>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'
[ 2014-08-10 07:09:08.7874 733/7f2624c8d700 agents/HelperAgent/RequestHandler.h:2305 ]: [Client 20] Cannot checkout session
because a spawning …Run Code Online (Sandbox Code Playgroud) 我有一个Rails应用程序,我正在尝试根据表单中选择的区域选择设施列表.到目前为止,我已经实现了group_collection_select来执行此操作以及一些CoffeeScript.
它在创建新记录和选择区域时有效.该行为仅显示为所选区域列出的设施.什么不起作用是在编辑记录时,选择设施会显示按地区分组的所有设施,而不是将设施约束到所选区域.
如果我选择另一个区域然后选择原始原因,则会显示正确的设施列表.
我想学习如何将CoffeeScript重构到编辑记录时,在页面加载(编辑时)和更改时都会触发该函数.
最后,有一些用例,当transfer_from_id设置为nil/blank时,我们使用一个名为transfer_from_other的文本字段.目前,如果我没有选择设施并填写transfer_from_other,由于CoffeeScript加载transfer_from_id中的设施,它将通过范围中的第一个设施设置transfer_from_id.我想将其设置为如果没有选择任何设施,transfer_from_id为零,所以我可以使用transfer_from_other.
这是我的代码的样子:
calls.js.coffee
jQuery ->
facilities = $('#call_transfer_from_id').html()
$('#call_region_id').change ->
region = $('#call_region_id :selected').text()
options = $(facilities).filter("optgroup[label=#{region}]").html()
if options
$('#call_transfer_from_id').html(options)
else
$('#call_transfer_from_id').empty()
Run Code Online (Sandbox Code Playgroud)
region.rb
has_many :facilities
Run Code Online (Sandbox Code Playgroud)
facility.rb
attr_accessible :region_id
belongs_to :region
Run Code Online (Sandbox Code Playgroud)
_form.html.erb摘录
<%= f.label :region %>
<%= f.collection_select(:region_id, Region.all, :id, :area, {:include_blank => true}, {:class => 'select', required: true}) %>
<%= f.label :Transfer_From %>
<%= f.grouped_collection_select :transfer_from_id, Region.order(:area), :active_facilities, :area, :id, :facility_name, {include_blank: true}, class: 'select' %>
<%= f.label :Transfer_From_Other%>
<%= f.text_field :transfer_from_other %>
Run Code Online (Sandbox Code Playgroud)
如果我的问题和示例不清楚,请告诉我,我将很乐意编辑.
我正在使用Ruby 2.2.2运行El Capitan(全新安装)和Rails 4.2.1应用程序.我最初遇到了安装libv8的问题,不得不强制安装brew install v8和gem install libv8(version),并将systemv8作为标志.Bundle工作正常并安装所有gem依赖项.
但是当我去加载rails s或bundle exec thin start启动我的应用服务器时,我收到以下错误.
dyld: lazy symbol binding failed: Symbol not found: __ZN2v82V821AddGCPrologueCallbackEPFvNS_6GCTypeENS_15GCCallbackFlagsEES1_
Referenced from: /Users/shakycode/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-15/2.2.0-static/therubyracer-0.12.2/v8/init.bundle
Expected in: flat namespace
dyld: Symbol not found: __ZN2v82V821AddGCPrologueCallbackEPFvNS_6GCTypeENS_15GCCallbackFlagsEES1_
Referenced from: /Users/shakycode/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-15/2.2.0-static/therubyracer-0.12.2/v8/init.bundle
Expected in: flat namespace
Run Code Online (Sandbox Code Playgroud)
我正在谷歌搜索和寻找答案,但到目前为止还没有提出太多的工作.我升级到El Capitan的另一台机器没有问题,但这种干净安装对于libv8/v8/therubyracer来说是个问题.
关于如何调试这个的任何想法?我想要编码.
我有一个名为dispatched_time的日期时间,我从Time.now中减去它,结果是一个浮点数,即:302.332,这是一个名为elapsed_time的方法。我需要找到一种方法来获取该数字的值并将其格式化为我认为的时间。即:13:20。
我尝试使用 elapsed_time.strftime("%H%M") 但 strftime 不会处理浮点数。
有人可以帮我将秒内的浮点数转换为 HH:MM 格式吗?
这可能是一个新问题,但我想我会问。我有一个运行 Devise 2.1.2 的 Rails 3.2.14 应用程序。我想做的是,当用户使用不正确的电子邮件、用户名或密码登录时显示一条错误消息(我目前正在使用 Devise 根据电子邮件或用户名进行身份验证)。会话/新视图中应显示闪存通知,但不确定要提取什么。
我在 application.html.erb 中有以下设置来显示 Flash 通知:
<% if flash[:notice] %>
<p class="alert"><%= flash[:notice] %></p>
<% end %>
Run Code Online (Sandbox Code Playgroud)
但当尝试使用不正确的凭据登录时,它不会显示任何错误消息。但是,当我成功登录时,它会通过闪光通知/警报显示已成功登录。
目前,当您输入不正确的凭据时,屏幕只会刷新,而不会发出任何闪烁通知。知道我的 devise/sessions/new.html.erb 文件中应包含哪些内容吗?
任何帮助是极大的赞赏。我确信我错过了一些简单的事情。
我有一个用户模型,其中有一个电子邮件地址为user@domain.com
我想要做的是能够更新系统中的所有用户,以将其域名从@ domain.com更改为@ newdomain.com
有什么方法可以运行命令(update_all)或类似的命令来查找结尾部分(@ domain.com),并将其更改为@ newdomain.com?
如果我必须通过控制台或Rails_Admin一步一步地做到这一点,只是希望有一种方法可以以编程方式进行此操作。
我有一个Rails 3.2.21应用程序,其中我使用select的形式是这样的帮助:
<%= f.select :phys_option, options_for_select([["N/A", "n/a"], ["No", "no"], ["Yes", "yes"]], :selected => @call.phys_option), :include_blank => true, :required => true, :class => 'select' %>
Run Code Online (Sandbox Code Playgroud)
这适用于选择选项的基本功能,包括空白选项等.但是不起作用的是:required => true或者:class => 'select'.即使选择为空,我也可以提交表单,而我的select2 gem类select不适用于这个帮助方法.
我的语法错了还是我错过了什么?我可以调用模型验证来确保填写字段,但我宁愿避免更多模型验证并尝试使用:required => true强制选择.
为什么这不起作用的任何想法?
如果您需要更多细节和/或代码,请告诉我.
activerecord ×4
forms ×3
ruby ×3
datetime ×2
bundler ×1
capistrano ×1
coffeescript ×1
devise ×1
html5-audio ×1
jquery ×1
libv8 ×1
link-to ×1
macos ×1
nginx ×1
passenger ×1
therubyracer ×1
v8 ×1