我有这个条件,检查该国家是否在美国
if params[:address][:country] != 'United States'
logger.info "I am in here"
@address.errors.add(:base, "We're sorry, you cant update your address")
@address.errors.add(:country, "We're sorry, you cant update your address")
end
if @address.update_attributes(params[:address])
flash[:notice] = 'Information was successfully updated.'
Run Code Online (Sandbox Code Playgroud)
但我假设如果你在一个对象的基础上添加了一个错误,它就会暂停,但没有任何东西停止更新,闪存通知总是会出现......我如何阻止它并添加一个flash错误代替
我有一个rails表单用于创建具有隐藏字段的用户:
= hidden_field_tag "user[site_ids][]", @current_site.id, :data => @current_site.id, :class => 'current_site_id'
Run Code Online (Sandbox Code Playgroud)
它设置current_site的site_id.
我还有一些复选框列出了所有网站:
- Site.all.each do |site|
%label.checkbox
= check_box_tag 'user[site_ids][]', site.id, false, :class => "sites_checkbox"
= site.name
Run Code Online (Sandbox Code Playgroud)
我有隐藏字段的原因是如果用户没有选择它至少会设置的任何复选框@current_site.
我正在考虑使用这样的JQuery:如果用户选择其中一个复选框,我将值设置为999,而不是在db中:
$(".roles_selected").click(function() {
var selected = $(this).closest("label");
if (selected.attr("data") == 'superadmin') {
$('.current_site_id').val(999);
} else {
$('.current_site_id').val($('.current_site_id').attr('data'));
}
});
Run Code Online (Sandbox Code Playgroud)
并且在控制器中可以从中移除999 params[:user][:site_ids]
这似乎是如此hackish ......还有其他想法吗?
好的,所以我有一个数组:
numbers = ["2", "3", "4", "5"]
Run Code Online (Sandbox Code Playgroud)
我需要使用条件将数组拆分为两个数组
numbers.reject!{|x| x > 4 }
Run Code Online (Sandbox Code Playgroud)
我需要的是一个numbers包含的numbers = ["5"]数组和另一个包含拒绝的数组rejects = ["2", "3", "4"]
我该怎么做呢?...循环似乎很容易,但有没有办法在一个班轮中做到这一点?
你如何评论和取消注释与janus macvim的代码块
nerdcommenter的janus文档说绑定是
Janus binds command-/ (`<D-/>`) to toggle comments
Run Code Online (Sandbox Code Playgroud)
这在键击中意味着什么...我的领导键是逗号
UPDATE
在阅读了nerdcommenter doc后,似乎这可能不是我需要评论的......任何想法
我有一个PHP脚本,我通过命令行运行,如
php file.php
Run Code Online (Sandbox Code Playgroud)
在那个文件中,我有一个类似的打印声明
print "<br>Saved the url: {$url} to :{$destination}";
Run Code Online (Sandbox Code Playgroud)
我认为br会把它比另一个低1但是当我运行脚本时我会得到这种格式,这真的很难读
<br>Saved the url: http://example.com/a.mp3 to :/usr/recordings/3e/1555141317-2349577.mp3<br>Saved the url: http://example.com/b.mp3 to :/usr/recordings
Run Code Online (Sandbox Code Playgroud)
所以在控制台中很难读取格式.有没有办法重构我的打印,以获得这样的输出
Saved the url: http://example.com/a.mp3 to :/usr/recordings/3e/1555141317-dadfdasffa.mp3
Saved the url: http://example.com/b.mp3 to :/usr/recordings/3c/1555141317-fddfd.mp3
Saved the url: http://example.com/c.mp3 to :/usr/recordings/3f/1555141317-ffdfd.mp3
Run Code Online (Sandbox Code Playgroud) firebug抱怨它有语法错误
if (document.getElementById("fromAddress").value == "") ||
(document.getElementById("fromAddress").value == "Enter Address, City, Directions") {
Run Code Online (Sandbox Code Playgroud) as a
limit 0,50
ORDER BY SortOrder, paid desc, ae desc, name asc, title asc
Run Code Online (Sandbox Code Playgroud)
错误1064(42000):您的SQL语法有错误; 查看与您的MySQL服务器版本对应的手册,以获得正确的语法,在第48行的'ORDER BY SortOrder,付费desc,ae desc,名称asc,titile asc'附近使用
>> events.first.datetime
=> Wed Sep 15 19:00:00 -0400 2010
>> Time.parse(events.first.datetime)
NoMethodError: private method `gsub!' called for Wed Sep 15 19:00:00 -0400 2010:Time
Run Code Online (Sandbox Code Playgroud) 我该如何修剪呢?
$('#type_of_station').text()
Run Code Online (Sandbox Code Playgroud)
结果是
>>> $('#type_of_station').text()
"pizza delivery system "
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,在最后一个单词后面有一个空格
我有一个node.js应用程序,我有一个public/somehting.js文件是客户端,然后我有一个控制器文件controllers/something.js和models/something.js进行数据库连接.
如何从公共目录中访问服务器端信息的任何想法
我的模特/ features.js
exports.getFeatureClass = function(Sequelize, sequelize) {
sequelize.define("Feature", {
project_id: Sequelize.INTEGER,
title: Sequelize.STRING,
});
};
Run Code Online (Sandbox Code Playgroud)
我的公开/ featurepane.js
var FeaturePane = function FeaturePane(scope) {
console.log("hi");
//how to I access Db
};
Run Code Online (Sandbox Code Playgroud)