我有下一个HTML:
<label for="user_name">
<abbr title="required">*</abbr>
Name
</label>
Run Code Online (Sandbox Code Playgroud)
我想Title用jquery 更改标签标题.所以我这样做
$('label[for=user_name]').html('Title')
Run Code Online (Sandbox Code Playgroud)
它取代所有内部html(带abbr标签)
那么,最简单的替换方法是Name什么呢?
我想了解什么是git分支名称的最大允许大小.
我正在尝试创建一些长名称(作为实验),所以370个字符的名称是有效的,但380个字符给了我 fatal: Failed to lock ref for update: File name too long
所以问题是:git branch name中可以包含的最大字符数是多少?它取决于系统吗?是否可以在存储库中创建长分支名称,该名称将在远程存储库(即Github)上被拒绝?
使用simple_form和Bootstrap时遇到问题3.关于输入的包装器标签.显示以下代码:
查看代码(带haml)
= simple_form_for @refer_email_form, url: create_refer_message_path, html: { class: "form-horizontal" } do |f|
= f.input :to, label_html: { class: "col-sm-2" }
= f.input :subject, label_html: { class: "col-sm-2" }
Run Code Online (Sandbox Code Playgroud)
配置/ simple_form_bootstrap.rb
SimpleForm.setup do |config|
config.input_class = "form-control"
config.wrappers :bootstrap, tag: 'div', class: 'form-group', error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label, class: "control-label"
# b.wrapper tag: 'div', class: "col-sm-6" do |ba|
b.wrapper tag: 'div' do |ba|
ba.use :input
ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' …Run Code Online (Sandbox Code Playgroud) 我用我的导轨项目使用Pow和powify gem.
现在我尝试升级我的ruby版本(从1.9.3升级到2.0.0,我使用RVM)
当我切换ruby版本时,安装所有gem依赖项,我确保通过运行rails s和访问应用程序正常工作localhost:3000
我以前通过访问http://my_app.devpow来浏览我的应用程序.升级后,由于错误,此URL无法正常工作Bundler::RubyVersionMismatch: Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0
我尝试了什么:
此错误仍然存在.顺便说一句,我有另一个rails应用程序,最初使用ruby 2.0并使用pow ok.
我有一个轨道 button_to,我希望它在继续之前显示一个确认对话框。
<%= button_to("Rebuild indexes", action: "rebuild_indexes", data:
{confirm: "Are you sure you want to reset the indexes?" }) %>
Run Code Online (Sandbox Code Playgroud)
操作正在发生,但我没有收到确认框。我读到这个问题可能与javascript有关。我以为我已经启用了。
application.js
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require jquery.turbolinks
//= require turbolinks
//= require tinymce-jquery
//= require ckeditor/init
//= require ckeditor/config.js
//= require jquery.are-you-sure
//= require script
//= require script.responsive
//= require_tree .
Run Code Online (Sandbox Code Playgroud)
如果我对按钮进行检查,我会看到
<form class="button_to" method="post" action="/help/rebuild_indexes?data%5Bconfirm%5D=Are+you+sure+you+want+to+reset+the+indexes%3F">
<input type="submit" value="Rebuild indexes">
<input type="hidden" name="authenticity_token" value="3mnAMmyHaINiDngjQn87EMmhmetp2VJcX+lwcmbUlhwBfv7V1hpLc9ZY1OF5JAFm9erFJjX+qyDz35/KK41jaA=="> …Run Code Online (Sandbox Code Playgroud) 我使用postgresql通过Vagrant虚拟机制作,并希望将其用作我的rails应用程序数据库.
我使用类似的Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.network :private_network, ip: "192.168.33.18"
config.vm.provision :chef_solo do |chef|
# I take cookbook from https://github.com/opscode-cookbooks/postgresql
chef.add_recipe "postgresql::server"
chef.json = {
postgresql: {
config: {
ssl: false,
listen_addresses: '*'
},
password: {
postgres: 'postgres'
}
}
}
end
end
Run Code Online (Sandbox Code Playgroud)
接下来,我vagrant up希望接下来database.yml会有效:
development:
database: app_development
adapter: postgresql
host: '192.168.33.18'
username: root
Run Code Online (Sandbox Code Playgroud)
但这不会发生.. Rake任务失败并出现错误:
could not connect to server: Connection refused
Is the server running on host "192.168.33.18" and accepting
TCP/IP connections on port 5432? …Run Code Online (Sandbox Code Playgroud) 当我部署到pre服务器时,一切都很好.但如果我尝试部署到staging服务器,我会收到此错误:
bundler: command not found: bin/delayed_job
档案 - config/deploy/staging.rb
set :rails_env, 'staging'
set :eager_load, :true
set :unicorn_rack_env, 'staging'
role :app, %w{deploy@x.x.x.x}
role :web, %w{deploy@x.x.x.x}
role :db, %w{deploy@x.x.x.x}
set :rvm_type, :auto # Defaults to: :auto
set :rvm_ruby_version, '2.1.2'
set :rails_env, 'staging'
set :eager_load, :true
role :app, %w{deploy@x.x.x.}
role :web, %w{deploy@x.x.x.}
role :db, %w{deploy@x.x.x.}
set :rvm_type, :auto # Defaults to: :auto
set :rvm_ruby_version, '2.1.2'
set :deploy_to, '/var/www/app'
server 'x.x.x', user: 'deploy', roles: %w{web app} , port: 222
set …Run Code Online (Sandbox Code Playgroud) 这是我想要的一个例子.
我们有2个表 - 用户和部门
users:
id name d_id
1 Alice 1
2 Bob 1
departments:
id name
1 Sales
2 Support
Run Code Online (Sandbox Code Playgroud)
接下来,我写通常的右连接:
SELECT u.id, u.name, d.name AS d_name
FROM users u
RIGHT OUTER JOIN departments d ON u.d_id = d.id
Run Code Online (Sandbox Code Playgroud)
它返回:
id name d_name
-- -------- ---------
1 Alice Sales
2 Bob Sales
NULL NULL Support
Run Code Online (Sandbox Code Playgroud)
是否可以编写查询,返回下一个结果?
id name d_name
-- -------- ---------
1 Alice Sales
2 Bob Sales
NULL NULL Sales
NULL NULL Support
Run Code Online (Sandbox Code Playgroud) 我正在尝试生成位于半径为5公里的圆内的随机坐标(纬度,长度),其中心点位于某个坐标(x,y)处.我试图用红宝石编码,我正在使用该方法但不知何故,我得到的结果不在指定的5公里范围内.
def location(lat, lng, max_dist_meters)
max_radius = Math.sqrt((max_dist_meters ** 2) / 2.0)
lat_offset = rand(10 ** (Math.log10(max_radius / 1.11)-5))
lng_offset = rand(10 ** (Math.log10(max_radius / 1.11)-5))
lat += [1,-1].sample * lat_offset
lng += [1,-1].sample * lng_offset
lat = [[-90, lat].max, 90].min
lng = [[-180, lng].max, 180].min
[lat, lng]
end
Run Code Online (Sandbox Code Playgroud) 我有一些结构定义
defmodule Foo do
defstruct [:a, :b]
end
Run Code Online (Sandbox Code Playgroud)
我有一些结构
a = %Foo{a: 1, b: 2}
Run Code Online (Sandbox Code Playgroud)
我能够使用管道(如地图)获得新的结构
%Foo{a | b: 3}
%Foo{a: 1, b: 3}
Run Code Online (Sandbox Code Playgroud)
但与 map 不同的是,当变量中的键时,我无法获取新结构:
iex(4)> key = :b
:b
iex(5)> %Foo{a | key => 3}
** (CompileError) iex:5: unknown key key for struct Foo
Run Code Online (Sandbox Code Playgroud)
问题:当我有更新变量的密钥时如何获得新结构?
我不能强烈地提出我现在需要的东西,但这个想法是这样的:
用户输入一些看起来像模板的字符串
'Welcome to #{country}!' # or 'Welcome to %%country%%!', it's not essential
Run Code Online (Sandbox Code Playgroud)
是否有一些宝石(或可能是像Erb这样的标准工具),可以做两件事:
验证给定的字符串(即,如果我允许仅country作为参数传递,则具有其他参数的字符串将无效)
使用传递的参数插入给定的字符串(即some_method('Welcome to #{country}!', country: 'Russia')) # => 'Welcome to Russia!')
我正在尝试在我的新机器上安装 Rails,但在捆绑时不断收到此错误。
An error occurred while installing puma (4.3.5), and Bundler cannot
continue.
Make sure that `gem install puma -v '4.3.5' --source 'https://rubygems.org/'`
succeeds before bundling.
In Gemfile:
puma
Run Code Online (Sandbox Code Playgroud)
当我运行时gem install puma -v '4.3.5' --source 'https://rubygems.org/,我收到此错误:
Building native extensions. This could take a while...
ERROR: Error installing puma:
ERROR: Failed to build gem native extension.
current directory: /Users/christopherdavis/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/puma-4.3.5/ext/puma_http11
/Users/christopherdavis/.rbenv/versions/2.7.1/bin/ruby -I /Users/christopherdavis/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0 -r ./siteconf20200829-23175-2h0q0u.rb extconf.rb
checking for BIO_read() in -lcrypto... yes
checking for SSL_CTX_new() in -lssl... yes
checking for …Run Code Online (Sandbox Code Playgroud) 说我有下一个代码:
class Foo < ActiveRecord::Base
def self.bar
all.each(&:bar)
end
def bar
# do something that I want stub in test
end
end
Run Code Online (Sandbox Code Playgroud)
现在我要创建测试(Rspec):
foo = Foo.create
expect(foo).to receive(:bar)
Foo.bar
Run Code Online (Sandbox Code Playgroud)
此测试未通过,因为Foo.bar调用同一模型的其他实例foo.
我之前在这种情况下编写了一些复杂的代码,例如:
expect_any_instance_of(Foo).to receive(:bar)
Run Code Online (Sandbox Code Playgroud)
但这并不好,因为没有信心foo接收消息(可能有几个实例).并且expect_any_instance_ofRspec维护者也不推荐.
你如何测试这样的代码,是最好的做法吗?
ruby ×3
postgresql ×2
activerecord ×1
capistrano3 ×1
chef-infra ×1
delayed-job ×1
elixir ×1
git ×1
github ×1
jquery ×1
puma ×1
rack-pow ×1
rbenv ×1
rspec ×1
rubygems ×1
rvm ×1
simple-form ×1
sql ×1
testing ×1
vagrant ×1