小编Sea*_*eal的帖子

Rails ActionController未知格式

我正在尝试渲染xlsx文件.但我一直在接受406/UnknowFormat.我做了正确的设置,也许我错过了什么?

Rails 4.2 app

gem 'axlsx'
gem "axlsx_rails"
gem 'zip-zip'
Run Code Online (Sandbox Code Playgroud)

配置/初始化/ MIME

Mime::Type.register "application/xlsx", :xlsx

调节器

respond_to do |format|
      format.xlsx { render xlsx: "create", template: "api/reports/create" }
end
Run Code Online (Sandbox Code Playgroud)

意见/ API /报告/ create.xlsx.axlsx

wb = xlsx_package.workbook
wb.add_worksheet(name: "Reports") do |sheet|
  sheet.add_row [@report_name]
end
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails actioncontroller axlsx

8
推荐指数
2
解决办法
1万
查看次数

每个Ruby都有未定义的方法

破败不堪.一个人可以有很多出价,这个特定的人只有一个出价.

在我的索引动作中我有 @bids = Bid.find_by_person_id(params[:person_id])

在我看来,我做到了

<% @bids.each do |bid| %>
   <%= bid.bid_amount %>
<% end %>
Run Code Online (Sandbox Code Playgroud)

NoMethodError: undefined method each' for #<Bid:0x007f988a346f00>在访问人员出价的索引视图时得到了.

这是因为这个人只有一个出价吗?我觉得不是这样,但除此之外我不知所措.

ruby activerecord ruby-on-rails

5
推荐指数
1
解决办法
483
查看次数

自定义字体在heroku中不起作用

使用Rails 4

我已经阅读了很多关于如何让我的自定义字体在heroku中工作的线程.他们在开发模式下本地工作,但当推到heroku时,他们不会出现.

我的@ font-face位于主样式表中

@font-face {
    font-family: 'caviar_dreamsregular';
    src: font-url('caviardreams-webfont.eot');
    src: font-url('caviardreams-webfont.eot?#iefix') format('embedded-opentype'),
         font-url('caviardreams-webfont.woff') format('woff'),
         font-url('caviardreams-webfont.ttf') format('truetype'),
         font-url('caviardreams-webfont.svg#caviar_dreamsregular') format('svg');
    font-weight: normal;
    font-style: normal;

}
Run Code Online (Sandbox Code Playgroud)

application.rb中

config.assets.paths << "#{Rails.root}/app/assets/fonts"
Run Code Online (Sandbox Code Playgroud)

我有预编译资产

rake assets:precompile
Run Code Online (Sandbox Code Playgroud)

Heroku日志中没有错误.

不能想出来,有没有人有任何建议?

更新:

访问我的手机上的网站,字体工作...清除计算机上的缓存,仍然无法在计算机上工作.

css ruby-on-rails heroku css3 ruby-on-rails-4

3
推荐指数
1
解决办法
2908
查看次数

在表中移动 &lt;td&gt; 元素

假设我有一个 html 表

|td,td,td|
|td|
Run Code Online (Sandbox Code Playgroud)

如果我想将底行的 td 移到该行的右侧。我该怎么做呢?另外,我不能使用 3 的 colspan。我需要将整个单元格移过来。

最终结果

|td,td,td|
|      td|
Run Code Online (Sandbox Code Playgroud)

html css

3
推荐指数
1
解决办法
9365
查看次数

Git 认为我是别人

突然 git 认为我是另一个人。它认为我是与我共事的人,但我找不到任何关于 git 为何如此认为的参考。我检查了系统级别、本地和全局级别的 git 配置,我检查了我的 ssh 密钥,不知道还有什么要检查的。也许我应该卸载 git?错误如下。

remote: Permission to myusername/mitty.git denied to personiworkwith.
fatal: unable to access 'https://github.com/myusername/mitty.git/': The requested URL returned error: 403
Run Code Online (Sandbox Code Playgroud)

git github

3
推荐指数
1
解决办法
698
查看次数

Rails命令错误

我即将开始在另一个Web应用程序上工作,我将目录更改为

/ rails_projects

并输入

铁路新空白

然后我得到这个错误

Error: Command not recognized
Usage: rails COMMAND [ARGS]

The common rails commands available for engines are:
 generate    Generate new code (short-cut alias: "g")
 destroy     Undo code generated with "generate" (short-cut alias: "d")

All commands can be run with -h for more information.

If you want to run any commands that need to be run in context
of the application, like `rails server` or `rails console`,
you should do it from application's directory (typically test/dummy). …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails ruby-on-rails-4

2
推荐指数
1
解决办法
3803
查看次数

Rails应用程序在本地运行,但在部署到Heroku时则不行

我的应用程序在本地工作.我部署到heroku并收到应用程序错误.我似乎无法弄清楚出了什么问题.在下面发布日志,有什么突出的吗?

错误

应用程序中发生错误,无法提供您的页面.请稍后重试.

如果您是应用程序所有者,请检查日志以获取详细信息.

日志

heroku日志

2014-07-04T04:40:15.871014+00:00 heroku[web.1]: State changed from starting to crashed
2014-07-04T04:40:16.982435+00:00 heroku[router]: at=error code=H10 desc="App crashed"     method=GET path="/" host=kitchen-ninja.herokuapp.com request_id=aa152804-e6f0-4a2f-9c27-   c9fb580272f3 fwd="100.1.249.244" dyno= connect= service= status=503 bytes=
2014-07-04T04:40:17.620440+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=kitchen-ninja.herokuapp.com request_id=a3c43716-35b3-43b5-9426-fb2f3f400c1b fwd="100.1.249.244" dyno= connect= service= status=503 bytes=
2014-07-04T04:40:17.783162+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=kitchen-ninja.herokuapp.com request_id=2a8c63d7-3906-48c7-85de-abe64c2fd247 fwd="100.1.249.244" dyno= connect= service= status=503 bytes=
2014-07-04T04:40:15.860319+00:00 heroku[web.1]: Process exited with status 1
Run Code Online (Sandbox Code Playgroud)

的Gemfile

source 'https://rubygems.org'
ruby '2.0.0'


gem 'rails', '4.0.2'
gem 'pg', …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails heroku heroku-postgres

2
推荐指数
2
解决办法
6628
查看次数

Sum Hash值Ruby

我有一系列哈希

players =  [{:id=>1, :name=>"Alda", :dice_count=>5, :hand=>[6, 5, 2, 4, 3]},
 {:id=>2, :name=>"Gonzalo", :dice_count=>5, :hand=>[1, 5, 1, 1]},
 {:id=>3, :name=>"Markus", :dice_count=>5, :hand=>[6, 2, 5, 1]},
 {:id=>4, :name=>"Luella", :dice_count=>5, :hand=>[4, 5, 1, 6, 5]}]
Run Code Online (Sandbox Code Playgroud)

我想总结:hand数组中每个值的大小.有一个简单的方法吗?

所以输出将是每个的总和:hand.size.在上面的例子中,输出将是18

ruby

2
推荐指数
1
解决办法
194
查看次数

如果它们不在数组中,则拒绝哈希内容

我有这个数组:

array = ["1", "2", "3", "4"]
Run Code Online (Sandbox Code Playgroud)

我有这个哈希数组:

ah = [
 {:id=>"1", :value=>"A"},
 {:id=>"2", :value=>"B"},
 {:id=>"3", :value=>"C"},
 {:id=>"4", :value=>"D"},
 {:id=>"5", :value=>"E"},
 {:id=>"6", :value=>"F"},
 {:id=>"7", :value=>"G"},
 {:id=>"8", :value=>"H"},
     ]
Run Code Online (Sandbox Code Playgroud)

我需要拒绝ah其id不在的任何哈希值array.

实现这一目标的最佳方法是什么?

ruby arrays hash

1
推荐指数
1
解决办法
76
查看次数