添加另一个迁移和偶尔决定删除和迁移后,我检查了我的schema.rb并看到了这个
create_table "users", force: :cascade do |t|
Run Code Online (Sandbox Code Playgroud)
我还没有提交这些更改,而且我已经有了这个
create_table "users", force: true do |t|
Run Code Online (Sandbox Code Playgroud)
现在我在每张桌子前面都有级联.什么是级联,它来自哪里?
我试图用underscore.js及其reduce方法对内部和数组中的对象值求和.但看起来我做错了什么.哪里是我的问题?
let list = [{ title: 'one', time: 75 },
{ title: 'two', time: 200 },
{ title: 'three', time: 500 }]
let sum = _.reduce(list, (f, s) => {
console.log(f.time); // this logs 75
f.time + s.time
})
console.log(sum); // Cannot read property 'time' of undefined
Run Code Online (Sandbox Code Playgroud) 当我单击rails_admin 导航中的国家/地区时,我得到
NameError in RailsAdmin::Main#index
uninitialized constant Country::Person
raise NameError.new("uninitialized constant #{candidates.first}", candidates.first)
Run Code Online (Sandbox Code Playgroud)
我使用的是用户模型而不是人员。我想我需要以某种方式配置它。但到哪里去做呢?
这是我的 Rails 管理初始化程序
## == Devise ==
config.authenticate_with do
warden.authenticate! scope: :user
end
config.current_user_method(&:current_user)
## == Cancan ==
config.authorize_with :cancan
### More at https://github.com/sferik/rails_admin/wiki/Base-configuration
config.model "User" do
edit do
field :admin
field :username
field :email
field :password
end
end
config.actions do
dashboard # mandatory
index # mandatory
new
export
bulk_delete
show
edit
delete
show_in_app
## With an audit adapter, you can add:
# history_index
# history_show …Run Code Online (Sandbox Code Playgroud) unscope在rails 中使用有什么意义.
Article.where('id > 10').limit(20).order('id asc').unscope(:order)
# which gives
SELECT * FROM articles WHERE id > 10 LIMIT 20
# and this without unscope
SELECT * FROM articles WHERE id > 10 ORDER BY id asc LIMIT 20
Run Code Online (Sandbox Code Playgroud)
但为什么不删除 .order('id asc')部分:
Article.where('id > 10').limit(20)
Run Code Online (Sandbox Code Playgroud) 如何在GitHub页面上使用'jekyll-multiple-languages-plugin'?
它在本地工作,但是当我将源推送到GitHub时出现以下错误:
The tag `t` on line 6 in `about.html` is not a recognized Liquid tag.
Run Code Online (Sandbox Code Playgroud)
导致错误的代码是:
{% t about.title %}
Run Code Online (Sandbox Code Playgroud) 我想在字符串中找到最长的重复字符序列.
例如:
"aabbccc" #=> ccc
"aabbbddccdddd" #=> dddd
Run Code Online (Sandbox Code Playgroud)
等等
在第一个例子中,ccc是最长的序列,因为c重复3次.在第二个例子中,dddd是最长的序列,因为d重复4次.
它应该是这样的:
b = []
a.scan(/(.)(.)(.)/) do |x,y,z|
b<<x<<y<<z if x==y && y==z
end
Run Code Online (Sandbox Code Playgroud)
但我想,有一些标志可以保持重复次数
在帖子索引页面上,我以这种方式列出所有帖子:
posts_controller.rb
def index
@posts = Post.includes(:comments).paginate(:page => params[:page]).order("created_at DESC")
end
Run Code Online (Sandbox Code Playgroud)
index.html.erb
<%= render @posts %>
Run Code Online (Sandbox Code Playgroud)
_post.html.erb
<%= gravatar_for post.user, size:20 %>
<%= link_to "#{post.title}", post_path(post) %>
<%= time_ago_in_words(post.created_at) %>
<%= post.comments.count %>
<%= post.category.name if post.category %>
Run Code Online (Sandbox Code Playgroud)
每页35个帖子
当我第一次在dev env中加载页面时,rack-mini-profiler显示此时间:1441.1 ms
几次重载后:~700 ms
我可以以某种方式减少这个时间和sql请求的数量?
如果它有帮助,这里是rmp图像:


我已经下载了这个repo (api-presentation)来试验rails应用程序中的api.
这是一篇带有视频的文章,解释什么是api以及如何使用它.... http://www.aomran.com/designing--building-restful-json-apis/
现在我正试图通过Postman扩展的POST请求添加记录,我正在试图:
param is missing or the value is empty: contact
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
这是一个错误的屏幕:

这个**符号在Ruby中意味着什么?
(1..5).map { |i| i**2 } # => [1, 4, 9, 16, 25]
Run Code Online (Sandbox Code Playgroud) activerecord ×2
ruby ×2
activeadmin ×1
api ×1
github-pages ×1
javascript ×1
jekyll ×1
json ×1
sql ×1