小编PSC*_*ell的帖子

AWS S3集成产生未定义的方法`match'

我正在使用Paperclip上传图像的简单项目.在我尝试将S3与Paperclip集成之前,一切都运行良好.在"上传"用户的图像后,我收到NoMethodError (undefined method 'match' for nil:NilClass):错误消息.这只有在我的S3配置运行时才会发生 - 如果我将文件评论完全上传.

我的配置:

development.rb:
....
....
  config.paperclip_defaults = {
  :storage => :s3,
  :s3_credentials => {
    :bucket => ENV['AWS_BUCKET_ID'],
    :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
  }
}
Run Code Online (Sandbox Code Playgroud)

我的型号:

 class User < ActiveRecord::Base
        has_attached_file :image_file, default_url: "/myapp/images/:style/missing.png"
        validates_attachment_file_name :image_file, matches: [/png\Z/, /jpeg\Z/, /tiff\Z/, /bmp\Z/, /jpg\Z/]
Run Code Online (Sandbox Code Playgroud)

控制台的整个错误输出:

NoMethodError (undefined method `match' for nil:NilClass):
  app/controllers/images_controller.rb:33:in `block in create'
  app/controllers/images_controller.rb:32:in `create'
Run Code Online (Sandbox Code Playgroud)

我试过的事情:

  • 我将AWS密钥和存储桶名称直接添加到代码中,而不是作为环境变量.

  • 如上所述,我在我的环境文件中注释掉了AWS配置,它似乎完美无缺.

值得一提的是,我之前安装了fog宝石以开始配置Google云端存储,但决定坚持使用S3.我曾经gem uninstall fog删除了宝石,但似乎有一些依赖关系留在后面.

ruby-on-rails amazon-s3 paperclip

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

Heroku安装Bundler然后抛出错误Bundler 2.0.1

我正在尝试将Rails应用程序部署到Heroku。自从我在那里部署任何东西已经有一段时间了,但是我对这里发生的事情一无所知。

这是一个相当基本的Rails 5应用程序。部署顺利通过Gemfile,然后失败,并出现错误,要求我安装Bundler v 2.0.1。这是日志的有趣之处:

remote:        Fetching devise 4.6.2
remote:        Installing sass-rails 5.0.7
remote:        Installing devise 4.6.2
remote:        Bundle complete! 26 Gemfile dependencies, 78 gems now installed.
remote:        Gems in the groups development and test were not installed.
remote:        Bundled gems are installed into `./vendor/bundle`
remote:        Post-install message from i18n:
remote:        
remote:        HEADS UP! i18n 1.1 changed fallbacks to exclude default locale.
remote:        But that may break your application.
remote:        
remote:        Please check your Rails app for 'config.i18n.fallbacks = true'. …
Run Code Online (Sandbox Code Playgroud)

heroku bundler ruby-on-rails-5

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

Rails中的Bootstrap Carousel

我正在处理一个文件夹里面有几个图像的项目.我有Bootstrap正在处理我的项目,并试图使用本教程在旋转木马上工作.它似乎非常适合我的需求,但我很难将它混合到我的Ruby视图中.这是我到目前为止所得到的:

<div id="myCarousel" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">
    <% @patient.images.each do |image| %>
    <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
    <% end %>
  </ol>

  <!-- Wrapper for slides -->

      <div class="carousel-inner" role="listbox">
       <div class="item active">
        <% @patient.images.each do |image| %>
        <%= image_tag image.image_file.url %>
        <% end %>
        </div>
      </div>


<!-- Left and right controls -->
  <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> …
Run Code Online (Sandbox Code Playgroud)

html css ruby-on-rails twitter-bootstrap

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

Ruby Mailer:错误的参数数量

我正在努力建立我的邮件,但我一直在努力:

参数个数错误(0表示1)

叫我疯了,但我觉得我正确定义了一切:

控制器(为简洁而截断):

def create
@cms484 = Cms484.new(cms484_params)

respond_to do |format|
  if @cms484.save
    SendLink.message(@cms484).deliver_later
    format.html { redirect_to cms484s_path, notice: 'Cms484 was successfully created.' }
    format.json { render :show, status: :created, location: @cms484 }
  else
    format.html { render :new }
    format.json { render json: @cms484.errors, status: :unprocessable_entity }
  end
end
Run Code Online (Sandbox Code Playgroud)

SendLink.rb:

    class SendLink < ApplicationMailer
    def message(cms484)
    @cms484 = cms484
    mail(
      :subject => 'Hello from Postmark',
      :to  => @cms484.recipient ,
      :from => 'info@mysite.com',
      :html_body => '<strong>Hello</strong> user!.',
  end
end
Run Code Online (Sandbox Code Playgroud)

任何人都能看到大海捞针还是我完全错过了其他东西? …

ruby mailer postmark

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

每个如果不是零 - Rails

我有一个具有付费布尔属性的发票模型.帐户和发票之间存在关联,我只想在视图中显示未付款的发票.

我用它来显示所有发票:

<table class="table">
  <thead>
    <tr>
      <th>Invoice Number</th>
      <th>Invoice Date</th>
      <th>Invoice Total</th>
    </tr>
  </thead>

  <tbody>
    <% @account.invoices.each do |invoice| %>
      <tr>
        <td><%= invoice.id%> </td>
        <td><%= invoice.created_at.time.to_formatted_s(:long)%> Zulu </td>
        <td><%= invoice.total %></td>
      </tr>
    <% end %>
  </tbody>
Run Code Online (Sandbox Code Playgroud)

但我不确定如何将结果限制在只paid显示nil的发票的地方.我试过:<% @account.invoices.each do |invoice| unless @account.invoices.paid == 'nil' %>但是遇到了错误.显然我的语法错了.有什么建议?

ruby ruby-on-rails

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