小编use*_*833的帖子

如何在协作上下文中处理bundler更新(Gemfile.lock)?

我是一个特定项目的独立程序员,但现在有其他人加入了合作者.只有我在图片中,bundler更新是顺利的,我从来没有想过Gemfile.lock被Git跟踪.

新协作者bundle install在克隆回购后运行,并Gemfile.lock更新如下:

Gemfile.lock的

@@ -141,7 +141,7 @@ GEM
       rack-ssl (~> 1.3.2)
       rake (>= 0.8.7)
       rdoc (~> 3.4)
-      thor (< 2.0, >= 0.14.6)
+      thor (>= 0.14.6, < 2.0)
     raindrops (0.10.0)
     rake (0.9.2.2)
     rdoc (3.12)
@@ -164,7 +164,7 @@ GEM
     sprockets (2.1.3)
       hike (~> 1.2)
       rack (~> 1.0)
-      tilt (!= 1.3.0, ~> 1.1)
+      tilt (~> 1.1, != 1.3.0)
     thor (0.16.0)
     tilt (1.3.3)
     treetop (1.4.10)
@@ -175,7 +175,7 @@ GEM …
Run Code Online (Sandbox Code Playgroud)

collaboration version-control ruby-on-rails bundler gemfile

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

如何在ruby中将单个数字编号设为两位数?

Time.new.month返回10月之前任何月份的单个数字表示(例如6月6),但我想要一个2位数格式(即6我想要的而不是06).

我写了以下解决方案,我要求看一些其他/更好的解决方案.

s = 6.to_s; s[1]=s[0]; s[0] = '0'; s #=> '06'
Run Code Online (Sandbox Code Playgroud)

ruby number-formatting

14
推荐指数
4
解决办法
2万
查看次数

仅显示rails中字符串的前x个单词

<%= message.content %>
Run Code Online (Sandbox Code Playgroud)

我可以显示这样的消息,但在某些情况下我只想显示字符串的前5个单词然后显示省略号(...)

ruby string ruby-on-rails

13
推荐指数
4
解决办法
1万
查看次数

如何使用rails,nginx和passenger配置`Access-Control-Allow-Origin`?

我无法Access-Control-Allow-Origin在Chrome中显示 - 我的最终目标是使用Rails为字体配置CORS,因此它适用于productionCloudFront.但就目前而言,我只是想让它发挥作用development.我可以看到标题通过curl,但不是Chrome.

我正在使用Rails 4.0,我已经尝试了以下所有......

我已经配置Gemfileapplication.rb根据rails 4的rack-cors示例:

的Gemfile

gem 'rack-cors', '~> 0.2.9', require: 'rack/cors'
Run Code Online (Sandbox Code Playgroud)

配置/ application.rb中

config.middleware.insert_before 'ActionDispatch::Static', 'Rack::Cors' do
    allow do
        origins '*'
        resource '*',
            :headers => :any,
            :methods => [:get, :options, :head]
    end
end
Run Code Online (Sandbox Code Playgroud)

rails console

2.0.0-p481 :001 > Rails.env
 => "development"
2.0.0-p481 :002 > Hello::Application.config.serve_static_assets
 => true
Run Code Online (Sandbox Code Playgroud)

庆典

curl -i http://localhost:5000/assets/OpenSans-Regular-webfont.woff

Content-Type: application/font-woff
Content-Length: 22660
Connection: keep-alive
Status: 200 OK
Cache-Control: …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails passenger nginx http-headers cors

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

Rails bundler:如何撤消bundle package?

我该如何撤消bundle package

我删除了所有内容,vendor/cache但在运行时重新安装bundle install.

ruby bundle ruby-on-rails package

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

该捆绑目前的铁轨锁定在4.0.4

Gemfile我做了以下改变:

-bash> git diff Gemfile
...
-gem 'rails', '4.0.4'
+gem 'rails', '4.0.5'
Run Code Online (Sandbox Code Playgroud)

然后我跑了bundle,得到一个停止显示的消息:

-bash> bundle
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
You have requested:
  rails = 4.0.5

The bundle currently has rails locked at 4.0.4.
Try running `bundle update rails`
Run Code Online (Sandbox Code Playgroud)

然后我bundle update rails根据上面的消息跑了,得到了以下内容(注意我正在跳线而没有变化).

-bash> bundle update rails
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Installing rake 10.3.2 (was 10.3.0)
Installing multi_json …
Run Code Online (Sandbox Code Playgroud)

bundle ruby-on-rails upgrade gemfile ruby-on-rails-4

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

Ruby on Rails标题化连字符名称

Rails标题化方法删除连字符,而大写方法不会将连字符后的单词大写.我想要跟随(通过编写方法):

"mary-joe spencer-moore" => "Mary-Joe Spencer-Moore"

"mary-louise o'donnell" => "Mary-Louise O'Donnell"
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails

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

Ruby正则表达式提取单词

我正在努力想出一个正则表达式,它可以将一个字符串拆分成单词,其中单词被定义为由空格包围的字符序列,或者用双引号括起来.我正在使用String#scan

例如,字符串:

'   hello "my name" is    "Tom"'
Run Code Online (Sandbox Code Playgroud)

应该匹配的话:

hello
my name
is
Tom
Run Code Online (Sandbox Code Playgroud)

我设法匹配双引号括起来的单词:

/"([^\"]*)"/
Run Code Online (Sandbox Code Playgroud)

但是我无法弄清楚如何将空白字符包围起来以获得'你好','是'和'汤姆',同时又不会搞砸'我的名字'.

任何帮助都将不胜感激!

ruby regex string cpu-word

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

Rails Ajax Jquery Delete之后提交Post请求

我试图用Ajax删除我的Rails模型的实例.

它发生在点击按钮上,我的代码如下所示:

$("#button").click(function(){ 
    $.ajax({
        type: "POST",
        url: "/slot_allocations/" + slotallocation_id,
        dataType: "json",
        data: {"_method":"delete"},
        complete: function(){
            $( "#SlotAllocationForm" ).dialog( "close" );
            alert("Deleted successfully");
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

我能够成功删除它,但是该delete方法总是跟随post服务器的请求来创建具有现有数据的新模型.这些是对服务器的请求.

1. POST http://localhost:3000/slot_allocations/1009 [HTTP/1.1 204 No Content  57ms]    
2. POST http://localhost:3000/slot_allocations [HTTP/1.1 302 Found  111ms]
3. GET http://localhost:3000/slot_allocations/1010 [HTTP/1.1 200 OK  185ms]
Run Code Online (Sandbox Code Playgroud)

#1发生在点击我的按钮上.不过,我也不太清楚为什么#2#3发生.

视图中有两个按钮:

<button id="button">Delete</button>
<div class="actions"><%= f.submit %></div>
Run Code Online (Sandbox Code Playgroud)

ajax jquery ruby-on-rails ruby-on-rails-3

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

使用Rails和jQuery文件上载将Content-Type设置为直接上传到S3

我在这个主题上看到了很多问题,但是我遇到的任何问题对我都有用,所以我在这里发布另一个......

我正在Ruby on Rails上尝试使用jQuery File Upload插件直接配置文件上传到Amazon S3 .我跟着非常有用的Heroku教程来完成初始设置.文件上传很好,但是它们都标记为Content-Type: binary/octet-streamS3,所以当它们在应用程序中提供时,所有文件都会下载而不是直接打开.

这是一个问题,因为我试图允许图像,PDF,音频或视频文件,所以我需要能够Content-Type从文件中获取正确的文件并将其传递给S3.在看在亚马逊AWS的-SDK文档宝石,我看到这一节有关添加.where(:content_type).starts_with("")到presigned后对象的末尾修改政策.但是,当我这样做时,它引发了一个错误:

<Error><Code>AccessDenied</Code>
<Message>Invalid according to Policy: Policy Condition failed: ["starts-with", "$Content-Type", ""]</Message>
Run Code Online (Sandbox Code Playgroud)

所以我添加content_type: ""了预先签名的post对象的opts哈希,现在它再次工作,但是所有文件默认为binary/octet-stream默认的所有文件默认为image/jpeg.这是我现在的代码:

调节器

def new
  @s3_direct_post = S3_BUCKET.presigned_post(
                  key: "uploads/#{SecureRandom.uuid}/${filename}",
                  success_action_status: 201,
                  acl: :public_read,
                  content_type: "").where(:content_type).starts_with("")
end
Run Code Online (Sandbox Code Playgroud)

_form.html.haml

:javascript
  $(function() {
    $('.directUpload').find("input:file").each(function(i, elem) {
      var fileInput    = $(elem);
      var form         = $(fileInput.parents('form:first'));
      var submitButton = form.find('input[type="submit"]');
      var progressBar  = $("<div class='bar'></div>"); …
Run Code Online (Sandbox Code Playgroud)

jquery content-type ruby-on-rails amazon-s3 jquery-file-upload

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