我有一个MYSQL表,其中有5列:
id bigint
name varchar
description varchar
slug
Run Code Online (Sandbox Code Playgroud)
我可以让MySQL自动生成slug的值作为名称+描述的256位哈希?
我现在使用PHP在保存之前生成slug的SHA256值.
通过自动,我的意思是看是否可以更改slug字段的默认值,是一个计算字段,它是名称+描述的sha256.
我已经知道如何将其创建为插入操作的一部分.
在我看来,我有以下几点:
<%= select("event", :event_id, events_ids_titles_hash, { :include_blank => true, :onchange => "alert_me_test()" }) %>
Run Code Online (Sandbox Code Playgroud)
alert_me_test()是:
<script type="text/javascript">
function alert_me_test()
{
alert ("this is a test")
}
</script>
Run Code Online (Sandbox Code Playgroud)
下拉列表看起来很好,但是当我从中选择时,没有任何反应.我期待一个警告框里面有"这是一个测试".
当我进行编辑时,我有以下代码:
<% if @panel.event_id %>
<%= select("panel", :event_id, events_ids_titles_hash, {:selected => @panel.event_id}, { :include_blank => true}) %>
Run Code Online (Sandbox Code Playgroud)
我的IDE(RubyMine)不希望接受"onchange"作为附加参数,并将其放在:selected或:include_blank参数哈希中的一个中不会产生错误,但它不起作用
<% if @panel.event_id %>
<%= 'Event is ' + events_ids_titles_hash.key(@panel.event_id) %>
<%= select("panel", :event_id, events_ids_titles_hash, {:selected => @panel.event_id}, { :include_blank => true, :onchange => "alert_me_test()"}) %>
<% else %>
<%= 'Select Event …Run Code Online (Sandbox Code Playgroud) 我正在尝试执行batch_get_item来从表中请求多个项目.我在DynamoDB文档中遵循PHP示例,但我没有得到我期望的结果.
以下是代码:
$batch_array = array ();
$batch_array[]= array ('HashKeyElement' =>
array( AmazonDynamoDB::TYPE_STRING => 'V1L3M5O5L1W8R5B6D2Q1S8V0B3R8M7A6R0X0'));
$options = array (
'RequestItems' => array(
'profile_dev' => array (
'Keys' => $batch_array
)
)
);
$result = $this->db->batch_get_item($options);
Run Code Online (Sandbox Code Playgroud)
我得到了一个很长的响应,而不是获取数据,而是从尾端包含相关信息:
[x-aws-body] => {"RequestItems":{"profile_dev":{"Keys":[{"HashKeyElement":{"S":"V1L3M5O5L1W8R5B6D2Q1S8V0B3R8M7A6R0X0"}}]}}} ) [body] => CFSimpleXML Object ( [__type] => com.amazon.coral.validate#ValidationException [message] => One or more parameter values were invalid: The provided key size does not match with that of the schema ) [status] => 400 ) )
Run Code Online (Sandbox Code Playgroud)
该表的hashKey是一个字符串.它有一个rangeKey,但我使用的是hashKey,所以我可以获得与hashKey匹配的所有行.我错过了什么?
出乎意料的是,我开始收到以下错误消息:
(in /Users/me/.rvm/gems/ruby-1.9.3-p125@mysql2/gems/rails-0.9.5)
rake aborted!
ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (available in RDoc 2.4.2+) instead.
/Users/me/.rvm/gems/ruby-1.9.3-p125@mysql2/gems/rails-0.9.5/Rakefile:3:in `<top (required)>'
Run Code Online (Sandbox Code Playgroud)
当我做rails s(在我的开发环境终端--Mac Mountain Lion).这个应用程序正在生产中,所以我去了生产环境,做了一个捆绑显示,并修改了我的Gemfile,以对这些gems版本进行编码.
这是我现在在我的本地开发环境中的内容(产生错误消息的原因).
actionmailer (3.2.3)
actionpack (3.2.3)
activemodel (3.2.3)
activerecord (3.2.3)
activeresource (3.2.3)
activesupport (3.2.3)
annotate (2.4.1.beta1)
arel (3.0.2)
bcrypt-ruby (3.0.1)
bootstrap-datepicker-rails (0.6.15)
bootstrap-sass (2.0.2)
builder (3.0.4)
bundler (1.1.3)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.6.1)
commonjs (0.2.6)
devise (2.0.4)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.4.0)
factory_girl (3.2.0)
factory_girl_rails (3.2.0)
hike (1.2.1)
i18n (0.6.4)
journey (1.0.4) …Run Code Online (Sandbox Code Playgroud) 我正在与远程团队合作开展一个项目.他们创建了一个分支(r_branch),当我在GitHub时我可以看到它:
master
r_branch (and it tells me that it's 6 ahead)
Run Code Online (Sandbox Code Playgroud)
当我做git branch -r时,这就是我得到的:
origin/HEAD -> origin/master
origin/master
Run Code Online (Sandbox Code Playgroud)
没有提到r_branch.有任何想法吗?
我一直在筛选MySQLi文档,据我所知,我无法使用PHP和MySQLi创建数据库.它是否正确?
Rails 4.2
RubyXL
Run Code Online (Sandbox Code Playgroud)
我正在使用RubyXL来创建工作簿.我可以把它写成磁盘:
workbook.write("path/to/desired/Excel/file.xlsx")
Run Code Online (Sandbox Code Playgroud)
然后用这样的东西下载它:
send_file(workbook.write("path/to/desired/Excel/file.xlsx"),options = {:filename =>'myworkbook.xlsx',:disposition =>'attachment'})
有关如何下载它而不必先将其保存到服务器的任何建议?
I have the following array of hashes:
books = [
{'author' => 'John Doe', 'month' => 'June', 'sales' => 500},
{'author' => 'George Doe', 'month' => 'June', 'sales' => 600},
{'author' => 'John Doe', 'month' => 'July', 'sales' => 700},
{'author' => 'George Doe', 'month' => 'July', 'sales' => 800}
]
Run Code Online (Sandbox Code Playgroud)
Out of this, how can I get an array, with the following:
[
{'author' => 'John Doe', 'total_sales' => 1200},
{'author' => 'George Doe', 'total_sales' => 1400}
]
Run Code Online (Sandbox Code Playgroud) 轨道7.1
在我的应用程序/服务/工具中,我有一个文件:services_tools.rb
在 services_tools.rb 中,我有:
module ServicesTools
class ErbToSlim
def convert_erb_to_slim(erb_file)
...........
end
end
class NestedMigrationCreator
def generate_nested_migration(migration_namespace:, migration_name:, migration_code: nil)
..........
end
end
end
Run Code Online (Sandbox Code Playgroud)
我进入命令行,然后执行以下操作:
rails c
Run Code Online (Sandbox Code Playgroud)
然后我这样做:
creator = ServicesTools::NestedMigrationCreator.new
Run Code Online (Sandbox Code Playgroud)
我收到以下消息:
(irb):1:in `<main>': uninitialized constant ServicesTools (NameError)
Run Code Online (Sandbox Code Playgroud)
在控制台中,当我这样做时:
ActiveSupport::Dependencies.autoload_paths
Run Code Online (Sandbox Code Playgroud)
我得到:
"/lib",
"/test/mailers/previews",
"/app/channels",
"/app/controllers",
"/app/controllers/concerns",
"/app/helpers",
"/app/jobs",
"/app/mailers",
"/app/models",
"/app/models/concerns",
"/app/services",
...
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
而不是标准的显示,编辑,删除,我在views/users/index.html.erb中有以下内容
<td>
<%= link_to user, class: 'btn btn-default' do %>
<span class="glyphicon glyphicon-search"></span>
<% end %>
</td>
<td>
<%= link_to edit_user_path(user), class: 'btn btn-default' do %>
<span class="glyphicon glyphicon-pencil"></span>
<% end %>
</td>
<td>
<%= link_to user, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' do %>
<span class="glyphicon glyphicon-remove"></span>
<% end %>
</td>
Run Code Online (Sandbox Code Playgroud)
如何在应用程序中的所有其他模型中重复使用此代码?
ruby-on-rails twitter-bootstrap ruby-on-rails-4 ruby-on-rails-4.1
Rails 3.2
Run Code Online (Sandbox Code Playgroud)
我有一个正在运行的 Rails 应用程序,带有 Company MVC。
在 models/company.rb 中,我有以下方法:
def save_company_pay_num
return false unless self.valid?
create_company_pay_num if self.company_pay_num.blank?
res = save_check_company_pay_num
unless res[0]
errors.add(:set_company_pay_num, res[1].try{|r| r.split(':')[1].strip.capitalize})
return false
end
true
end
Run Code Online (Sandbox Code Playgroud)
我有大约 1,000 家公司需要重新发放工资号码。
有没有办法从 Rails 控制台(rails c)执行文件,例如:
reset_pay_num.rb
company_ids=[
'1',
'2',
'3',
...
]
company_ids.each do |c|
company = Company.find(c)
company.save_company_pay_num
end
Run Code Online (Sandbox Code Playgroud) 我有一系列红宝石哈希:
my_array = [{"apples" => 5}, {"oranges" => 12}]
Run Code Online (Sandbox Code Playgroud)
我想将其转换为哈希,哈希键等于数组索引值+1,如下所示:
my_hash = {"1"=>{"apples"=> 5}, "2"=>{"oranges" => 12}}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?