我正在使用这样的东西:
case referer
when (referer.include? "some_string")
redirect_link = edit_product_path
when (referer.include? "some_other_string")
redirect_link = other_product_path
end
Run Code Online (Sandbox Code Playgroud)
不幸的是,即使字符串some_string存在于变量中,它也会返回nil referer.
这是我在Ruby控制台中尝试的内容:
ruby-1.8.7-p334 :006 > jasdeep = "RAILS"
ruby-1.8.7-p334 :026 > case jasdeep
ruby-1.8.7-p334 :027?> when (jasdeep.include? "AI")
ruby-1.8.7-p334 :028?> puts "Hello"
ruby-1.8.7-p334 :029?> end
=> nil
Run Code Online (Sandbox Code Playgroud)
任何输入将不胜感激.
我不小心跑了sudo bundle install smtp_mail,现在我的所有宝石都在smtp_mail我的Rails应用程序里面的这个目录中.
我不确定宝石的默认位置?而且,我的Rails应用程序在启动时抱怨.有没有办法可以恢复?
我有一个Rails应用程序与设计集成.我正在使用Cookie Store会话.每次有人登录时我都需要在会话中存储一些数据,例如.他们的用户ID.我怎么能用Devise这样做?
可能有一些优雅的方式,我只是不需要这样做,并可以使用Devise本身访问它.
谢谢!
任何人都可以通过Rails 3中的嵌套属性来引导我吗?
我有两个模型:证书和保管人,相关如下:
证书型号:
class Certificate < ActiveRecord::Base
belongs_to :shareholder
belongs_to :custodian
belongs_to :issuer
accepts_nested_attributes_for :custodian, :shareholder, :issuer
end
Run Code Online (Sandbox Code Playgroud)
证书控制器:
class CertificateController < ApplicationController
def issue
@certificate = Certificate.new
@certificate.custodian.build
end
end
Run Code Online (Sandbox Code Playgroud)
我的看法:
<% form_for(:certificate, :url => {:action => 'testing'}) do |f| -%>
<div id="error">
<%= f.error_messages %>
</div>
<%= f.label :number, "Certificate Number" %>
<%= f.text_field :number %> <br/>
<%= f.label :num_of_shares, "Number Of Shares" %>
<%= f.text_field :num_of_shares %> <br/>
<% f.fields_for :custodian do |custodian| -%>
<%= custodian.label …Run Code Online (Sandbox Code Playgroud) 给定一个整数数组,编写一个返回所有唯一对的方法,最多可加100.
示例数据:
sample_data = [0, 1, 100, 99, 0, 10, 90, 30, 55, 33, 55, 75, 50, 51, 49, 50, 51, 49, 51]
sample_output = [[1,99], [0,100], [10,90], [51,49], [50,50]]
Run Code Online (Sandbox Code Playgroud)
我本周末解决了这个问题,虽然我的解决方案似乎可扩展且高效,但我想确定解决方案的最坏情况时间复杂度是多少?
这是我的解决方案:
def solution(arr)
res = []
h = Hash.new
# this seems to be O(N)
arr.each do |elem|
h[elem] = true
end
# how do I determine what Time complexity of this could be?
arr.each do |elem|
if h[100-elem]
h[100-elem] = false
h[elem] = false
res << [elem, 100-elem] …Run Code Online (Sandbox Code Playgroud) ruby algorithm performance complexity-theory computer-science
我对Rails 3和Devise有一个特殊的问题.我的Rails应用程序有3种用户类型:
客户端,所有者和管理员
routes.rb中:
devise_for :admins
devise_for :owners
devise_for :clients
Run Code Online (Sandbox Code Playgroud)
application_controller.rb:
def after_sign_in_path_for(resource)
if resource == "client"
"/client_accounts/" + current_client.id.to_s
elsif resource == "admin"
stored_location_for(:admins) || "/admin/control_panel"
elsif resource == "owner"
stored_location_for(:owners) || "/client_accounts"
end
end
Run Code Online (Sandbox Code Playgroud)
我的登录所有者和管理员工作正常,但我无法让客户登录工作..这是我得到的错误:
NoMethodError in Devise/sessionsController#create
undefined method `client_url' for #<Devise::SessionsController:0x10a98f868>
Run Code Online (Sandbox Code Playgroud)
应用程序跟踪为空.
我的PHP中的爆炸功能有问题.
我从数据库中提取字符串如下:
column_name
0,2000,0,3000,1000,7000,1000,0,0,0
Run Code Online (Sandbox Code Playgroud)
将它拉入一个名为$ recordset的对象后,我正在使用explode函数从中创建一个数组......如下所示:
$array = explode(",",$recordset->column_name)
Run Code Online (Sandbox Code Playgroud)
但是有些怎么样,阵列并不像我期望的那样......
这是我回应数组时得到的结果:
Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 3000
[4] => 7000
[5] => 2000
[6] => 1000
[7] => 1000
[8] => 0
[9] => 0
)
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我没有得到我想要的值...但是,如果我的数据库中的字符串很短,请说:
1000,0,1200,0
Run Code Online (Sandbox Code Playgroud)
以上逻辑工作正常..
我不知道如何调试或解决这个问题..
请帮忙?
在父表和子表之间的一对多关联中.
是否可以将Child表上的Foreign键作为同一子表上的主键.
只是通过DBMS工作,并希望专家对这些类型的设计的看法.
优缺点都有什么?
我正在使用来自loopj.com的jquery tokeninput插件这是我的JS文件:
\n\n$(document).ready(function() {\n\n // Token input plugin:\n\n $("#issuer").tokenInput("/issuers.json",{\n crossDomain: false,\n theme: "facebook",\n prePopulate: $("#issuer").data("pre"),\n preventDuplicates: true\n });\n\n $("#shareholder").tokenInput("/shareholders.json",{\n crossDomain: false,\n theme: "facebook",\n prePopulate: $("#shareholder").data("pre"),\n preventDuplicates: true\n });\n\n});\nRun Code Online (Sandbox Code Playgroud)\n\n这是我的标记:
\n\n<form method="post" action="/certificates" accept-charset="UTF-8">\n<input type="hidden" value="\xe2\x9c\x93" name="utf8">\n<input type="hidden" value="fSO/GJxIGEHLCb/zmd1B7qTwUYnGx5yyIxWTkEk/ies=" name="authenticity_token">\\\n\n <div class="field">\n <label for="issuer">Issuer</label><br>\n <input type="text" size="30" name="certificate[issuer]" id="issuer" data-pre="[null]">\n </div>\n\n <div class="field">\n <label for="shareholder">Shareholder</label><br>\n <input type="text" size="30" name="certificate[shareholder]" id="shareholder" data-pre="[null]">\n </div>\n</form>\nRun Code Online (Sandbox Code Playgroud)\n\n我的 tokenize 插件可以工作#issuer,但不能工作,如果我使用顶部的选择器#shareholder移动 jQuery 代码,则令牌输入代码适用于,但不再适用于另一个。我怎样才能让它对他们俩都起作用?#shareholder#shareholder
另外,如果我在编辑模式下具有相同的表单和相同的标记 …
我有一个MySQL数据库和一个具有名称列的表,如下所示:
id name age
1 samuel lee 31
2 doug sokira 32
3 vernon smith 33
Run Code Online (Sandbox Code Playgroud)
我想在数据库中搜索名称.到目前为止我有这个问题:
SELECT * FROM table WHERE name LIKE 's%'
Run Code Online (Sandbox Code Playgroud)
这将返回ID为1的第一条记录.
但是,我希望查询进一步从空格分隔的文本中进行搜索.所以,换句话说,搜索应该通过名字和姓氏来完成.
我愿意坚持这个数据库设计,其中名字和姓氏存储在一个单独的列中.
因此,上面的查询应返回第1,2和3行.
我应该如何制定我的查询?