我得到奇怪ActionController::RoutingError: No route matches.可以生成路线:
> r = Rails.application.routes
> r.generate controller: :items, action: :index, user_id:1
=> ["/users/1/items", {}]
Run Code Online (Sandbox Code Playgroud)
它在rake routes:
$ rake routes
user_items GET /users/:user_id/items(.:format) items#index
POST /users/:user_id/items(.:format) items#create
new_user_item GET /users/:user_id/items/new(.:format) items#new
edit_user_item GET /users/:user_id/items/:id/edit(.:format) items#edit
user_item GET /users/:user_id/items/:id(.:format) items#show
PUT /users/:user_id/items/:id(.:format) items#update
DELETE /users/:user_id/items/:id(.:format) items#destroy
(...)
Run Code Online (Sandbox Code Playgroud)
但我不承认:
r.recognize_path "/users/1/items"
ActionController::RoutingError: No route matches "/users/1/items"
Run Code Online (Sandbox Code Playgroud)
我的routes.rb:
Sumo2::Application.routes.draw do
resources :users do
resources :items
end
(...)
end
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我想将我的最后一个 heroku postgres 备份发送到 S3 以将其存储在 heroku 基础架构之外,以防万一我在错误的数据库上单击“删除”。
为此,我需要一个指向备份的 URL。我试图运行heroku pg:backups public-url -q,但它在一次性测功机上不起作用(我试过heroku run bash测功机)。当 dynos 上似乎没有 heroku 工具带。
我以为我可以使用platform-api gem,但它似乎不支持 pg:backups。
你知道我如何在 heroku 调度程序上获取 pg 备份数据吗?或者也许您有更好的方法将数据库备份发送到 S3?
我正在尝试创建一个可以解析由大写单词后跟零个或多个封装在双引号中的参数组成的字符串的函数。
例如,以下每一行:
COPY "filename one" "filename two"
REMOVE "filename"
LIST "x" "y" "z"
DISCONNECT
Run Code Online (Sandbox Code Playgroud)
结果应该是一个字符串(命令),后跟一个字符串[](引号内的参数)。我创建了以下正则表达式:
re1, _ := regexp.Compile(`([A-Z]+)(?: "([^"]+)")*`)
results := re1.FindAllStringSubmatch(input, -1)
Run Code Online (Sandbox Code Playgroud)
然而,无论我如何尝试,只有最后一个参数被捕获。
我的问题的一个例子:https ://play.golang.org/p/W1rE1X4SWf5
"arg1"本例中未捕获。我缺少什么?
问题陈述: 如果发现有字母的特殊字符,则将其替换为一个空格。并且,如果发现它带有数字,则只需忽略即可。
实际场景:
$454.5 inchesTask.This is good.Hello, How $are you. This is good.预期场景:
$454.5 inchesTask This is goodHello How are you This is good我尝试编写一个正则表达式来找出遵循此模式的文本,但不确定如何用空格替换该文本中的特殊字符。
对于例如在上述的图像,期望的输出将是'ddddd dfhghg','222 d'等
这种情况可以通过 re.sub(pattern, replacement, input) 处理吗?如果是,请告诉如何:)
为什么这个正则表达式在 Python 中有效,而在 Ruby 中无效:
/(?<!([0-1\b][0-9]|[2][0-3]))/
Run Code Online (Sandbox Code Playgroud)
很高兴听到解释以及如何在 Ruby 中解决它
使用整行代码进行编辑:
re.sub(r'(?<!([0-1\b][0-9]|[2][0-3])):(?!([0-5][0-9])((?i)(am)|(pm)|(a\.m)|(p\.m)|(a\.m\.)|(p\.m\.))?\b)' , ':\n' , s)
Run Code Online (Sandbox Code Playgroud)
基本上,我试图添加'\n'冒号而不是时间。
I have an array of strings from which I need to extract the first words, convert them to integers and get the their sum.
Example:
["5 Apple", "5 Orange", "15 Grapes"]
Run Code Online (Sandbox Code Playgroud)
Expected output => 25
My attempt:
["5","5","15"].map(&:to_i).sum
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用活动记录和 csv 类导出数据,但我没有生成可以帮助查看代码的文件。
当我单击“导出”时,未打开从 csv 下载的对话框,我是否遗漏了某些内容?
我的控制器
def export_csv
@contact = Contacts.find_by_sql("select * from contacts_list limit 10")
respond_to do |format|
format.html
format.csv { send_data @contact.as_csv }
end
end
Run Code Online (Sandbox Code Playgroud)
我的模特
def self.to_csv
attributes = %w{id name mail}
CSV.generate(headers: true) do |csv|
csv << attributes
all.each do |contact|
csv << attributes.map{ |attr| contact.send(attr) }
end
end
end
Run Code Online (Sandbox Code Playgroud)
我的看法
<%= link_to( 'Export CSV' ,{ :controller => :company, :action => :export_csv, format: "csv"}, { :class => "btn-ex" } ) %>
Run Code Online (Sandbox Code Playgroud)
控制台输出
Started GET "/company/export_cs" …Run Code Online (Sandbox Code Playgroud) 作为预处理数据的一部分.我希望能够替换空格后跟一个数字,保持空格后跟一个字符.例如:
Input String: '8.1.7 Sep 2000 Dec 2004 Dec 2006 Indefinite'
Expected output: '8.1.7,Sep 2000,Dec 2004,Dec 2006,Indefinite'
Run Code Online (Sandbox Code Playgroud)
我在python中使用基于正则表达式的替换函数:
re.sub("\s+", ",", release)
Run Code Online (Sandbox Code Playgroud)
但这并没有取得理想的结果,只是因为这意味着要替换所有空格,不知道如何保持一个字符后跟即[a-z].
或许我需要重新思考方法.
我在这里看到了不同的答案,但不幸的是,这些答案都不适合我的情况.所以我希望你不介意.
所以我需要匹配两个大括号{}之间的所有内容,除了匹配以@开头且没有这些大括号的情况,例如:
这是我的测试字符串,1,2,3有效,而最后一个不应该是:
1 {eww}
2 r23r23{fetwe}
3 #{d2dded}
4 @{d2dded}
Run Code Online (Sandbox Code Playgroud)
我正在尝试:
(?<=[^@]\{)[^\}]*(?=\})
Run Code Online (Sandbox Code Playgroud)
然后只有第2和第3个选项匹配(没有第一个) https://regex101.com/r/qRInUf/2/
然后我在尝试:
\{(.*?)\} or [^@]\{(.*?)\}
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,我都无法匹配1,2,3值 https://regex101.com/r/uYRtLD/1
在此先感谢您的任何建议.
编辑:这是为java.
使用image_tag时,提供的Nil位置出现参数错误。如何使image_tag仅在存在相应图像时才显示的位置为可选?这是与Ruby on Rails 5一起使用的。
这是我当前的显示页面视图:
<p id="notice"><%= notice %></p>
<%= image_tag @restaurant.image_url %>
<p>
<strong>Name:</strong>
<%= @restaurant.name %>
</p>
<p>
<strong>Address:</strong>
<%= @restaurant.address %>
</p>
<p>
<strong>Phone:</strong>
<%= @restaurant.phone %>
</p>
<p>
<strong>Website:</strong>
<%= @restaurant.website %>
</p>
<%= link_to 'Edit', edit_restaurant_path(@restaurant), class: 'btn btn-link' %> |
<%= link_to 'Back', restaurants_path, class: 'btn btn-link' %>
Run Code Online (Sandbox Code Playgroud) regex ×5
ruby ×5
python ×3
activerecord ×1
amazon-s3 ×1
arrays ×1
csv ×1
go ×1
heroku ×1
java ×1
python-3.x ×1
regex-group ×1
routes ×1
string ×1