小编Liz*_*Liz的帖子

Heroku不显示SCSS背景图像

我有一个Rails应用程序,它使用style.css.scss文件中的背景图像.我发现了多种显示图像的localhost方法,但没有办法让它们在Heroku上显示.

我已经看了看所以像很多帖子这个这个,还有其他网站,如,但至今没有奏效.

这是我在我的代码style.css.scss:

.hero-000 {
    width: 102%;
    background: url(asset-path("hero-000.jpg")) no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}
Run Code Online (Sandbox Code Playgroud)

不过,我也尝试过background-image,image-url,asset-url,和许多其他排列作为连接,从而发现帖子.

我在我的production.rb文件中有这个:

  config.serve_static_files = true
  config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
  config.assets.compile = true
  config.assets.digest = true
Run Code Online (Sandbox Code Playgroud)

这在我的application.html.erb文件中调用css表:

  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
Run Code Online (Sandbox Code Playgroud)

正如其他帖子所建议的,我已将此添加到我的application.rb:

config.assets.initialize_on_precompile = false
Run Code Online (Sandbox Code Playgroud)

关于如何解决这个问题的任何想法都会很高兴收到!

附加信息

这是我的gemfile:

source 'https://rubygems.org'

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

css ruby-on-rails heroku

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

使用JQuery的CSS3动画触发器单击其他元素

我在我的Rails应用程序中有一个类似reddit的upvote/downvote情况,我正在尝试制作CSS3动画,以便当用户点击任何downvote链接时它会触发动画.

我正在使用这样的JQuery:

<div class="animations">
  <%= image_tag "ballerino.png", class: "fixed no-display", id: "to-animate", style: "margin-top: 80px; width: 40%" %>

  <script>
    $("#downvote").on('click',function() {
      $('#to-animate').removeClass('fixed');
      $('#to-animate').removeClass('no-display');
      $('#to-animate').addClass('animation-left-to-right');
    });
  </script>

</div> <!-- animations -->
Run Code Online (Sandbox Code Playgroud)

进一步在页面上作为每个Joke对象的渲染部分:

<div class="text-center col-xs-1">
  <% if current_user %>
    <div class="width: 100%"><%= link_to " ", joke_up_vote_path(joke), id: "upvote", class: 'glyphicon glyphicon-chevron-up', method: :post, style: "margin-right: 0; margin-left: 0" %></div>
  <% else %>
    <div class="width: 100%"><%= link_to " ", new_user_session_path, id: "upvote", class: 'glyphicon glyphicon-chevron-up', method: :post, style: "margin-right: 0; …
Run Code Online (Sandbox Code Playgroud)

jquery ruby-on-rails css3

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

Rails 5.2的ActiveStorage图像上传错误:signed_id委托给附件,但附件为零

我在使用ActiveStorage上传图像/ pdf时出现问题.图像似乎没有问题上传,但是当我尝试显示它们时它们会导致错误.

我的blog模特has_one_attached :imagehas_one_attached :pdf.上传曾经工作(所以我知道我安装了ActiveStorage,我的亚马逊s3设置正确),但出了点问题.

唯一复杂的一点是我需要它才能工作,如果它有PDF或不(不是所有的博客都有一个PDF ...所有应该有一个图像).

我的blog#create方法是:

  def create
    @blog = Blog.new(blog_params)
    @blog.user_id = current_user.id
    if @blog.published
      @blog.published_on = DateTime.current
    end

    respond_to do |format|
      if @blog.save
        if @blog.image.attached?
          @blog.image.purge
        end
        @blog.image.attach(params[:image])
        if @blog.pdf.attached?
          @blog.pdf.purge
        end
        @blog.pdf.attach(params[:pdf])
        format.html { redirect_to @blog, notice: 'Blog was successfully created.' }
        format.json { render :show, status: :created, location: @blog }
      else
        format.html { render :new }
        format.json { render json: @blog.errors, status: :unprocessable_entity }
      end
    end …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails-5 rails-activestorage

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

尝试使用Rails ActiveStorage和Amazon aws s3直接上传时出现控制台错误

我正在尝试使用ActiveStorage和aws s3替换带有图像上传的折旧(对于Rails 5.2)回形针.我正在使用指南和GoRails剧集,但遇到了我无法解析的控制台错误.在我的表单上看起来一切都很好,但是当我去提交时,我会在我的控制台中看到它:

activestorage.self-6e8d967adecc8b2a7259df0f51ef5b6f171c33267c7d149a474beccd90c68697.js?body=1:1 POST http://localhost:3000/rails/active_storage/direct_uploads 500 (Internal Server Error)
Run Code Online (Sandbox Code Playgroud)

我在blogs#new_ 上有这个form.html.erb:

<div class="form-group">
  <%= f.label "Picture" %>
  <%= f.file_field :image, direct_upload: true %>
</div>
Run Code Online (Sandbox Code Playgroud)

我把它放在我的模型中:

has_one_attached :image
Run Code Online (Sandbox Code Playgroud)

我有:image我的参数

def blog_params
  params.require(:blog).permit(:title, :teaser, :body, :user_id, :tag_list, :link_text, :link_filename, :pillars_id, :image)
end
Run Code Online (Sandbox Code Playgroud)

我把它添加到我的storage.yml:

Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
amazon:
  service: S3
  access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %>
  secret_access_key: <%= ENV["AWS_SECRET_ACCESS_KEY"] %>
  region: us-west-1
  bucket: nameofbucket
Run Code Online (Sandbox Code Playgroud)

这在我的开发环境中:

config.active_storage.service = …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails amazon-s3

9
推荐指数
0
解决办法
436
查看次数

Rails 5.2错误更改或删除表列(SQLite3 :: ConstraintException:FOREIGN KEY约束失败:DROP TABLE)

我正在尝试完成从我的Blog表中更改其中一列的默认值的相当简单的壮举.我有以下迁移:

class UpdateBlogFields < ActiveRecord::Migration[5.2]
  def change
    change_column :blogs, :freebie_type, :string, default: "None"
  end
end
Run Code Online (Sandbox Code Playgroud)

相当简单,但运行时出现以下错误rake db:migrate:

StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE "blogs"
Run Code Online (Sandbox Code Playgroud)

我在尝试更改或删除列时会收到此错误,但在添加列时则不会收到此错误.

我的架构如下所示:

  create_table "blogs", force: :cascade do |t|
    t.string "title"
    t.string "teaser"
    t.text "body"
    t.string "category", default: "General"
    t.string "linked_module"
    t.boolean "published", default: false
    t.datetime "published_on"
    t.integer "user_id"
    t.integer "image_id"
    t.integer "pdf_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false …
Run Code Online (Sandbox Code Playgroud)

sql sqlite ruby-on-rails

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

Rails 5.2 Net::SMTPAuthenticationError - 535 Authentication failed: account disabled When Sending Email (Localhost and Heroku)

I'm trying to get a Rails 5.2 mailer working, but am coming across a Net::SMTPAuthenticationError - 535 Authentication failed: account disabled error on both localhost and my Heroku production environment.

The mailer looks like this:

class AdminNotificationsMailer < ApplicationMailer
  default from: "liz@linchpinindustries.com"

  def new_rfp(rfp)
    @rfp = rfp
    mail(
      :to => "liz@linchpinindustries.com",
      :subject => 'New RFP Alert!'
    )
  end

  def new_contact_us(contact)
    @contact = contact
    mail(
      to: "liz@linchpinindustries.com",
      subject: 'New Contact Us Submission on LPI'
    )
  end

end
Run Code Online (Sandbox Code Playgroud)

With the trigger in …

ruby-on-rails sendgrid

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

使用Delayed_Job发送电子邮件

我有我认为是通过发送电子邮件的工作设置Delayed_Job.但是,我还没有收到我的测试电子邮件,等待更多的事情发生延迟几天是不切实际的.我需要弄明白:

  1. 导致电子邮件不发送的错误是什么.
  2. 如何在不等待几天的情况下进行测试.

我是Delayed_Job新手,所以原谅新手的错误.

这是包含该send_reminder_emails方法的模型.它们完全没有功能.delay(run_at: self.mail_date),所以至少我知道它有多大功能:

class Reminder < ActiveRecord::Base
  belongs_to :user
  before_save :create_mail_date
  after_save :send_reminder_emails
  extend FriendlyId
  friendly_id :name, use: [:slugged, :finders]

  def create_mail_date
    @schedule = IceCube::Schedule.new(self.date)
    case self.repeating
    when "Weekly"
        @schedule.add_recurrence_rule(
            IceCube::Rule.weekly
        )
    when "Monthly"
        @schedule.add_recurrence_rule(
            IceCube::Rule.monthly.day_of_month(self.date.mon)
        )
    when "Yearly"
        @schedule.add_recurrence_rule(
            IceCube::Rule.yearly.day_of_year(self.date.yday)
        )
    end
    if self.repeating
        self.date = @schedule.next_occurrence(Time.now)
    end
    self.mail_date = self.date - 7.days
  end

  private

  def send_reminder_emails
      if self.reminder
         ReminderMailer.delay(run_at: self.mail_date).reminder_send(self.user, self).deliver_now
         self.create_mail_date
     end
  end
  handle_asynchronously :send_reminder_emails

end …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails actionmailer delayed-job

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

带有Rails的AJAX Devise表单不更新数据

我在我的应用程序上设置了一个Devise表单,用于从不同的页面(charges#new)更新用户信息的一部分(送货地址字段),服务器输出似乎表明它正在工作:

Started PUT "/users" for ::1 at 2017-05-11 17:10:52 -0700
Processing by RegistrationsController#update as JS
  Parameters: {"utf8"=>"?", "user"=>{"street_address_1"=>"**street address**", "street_address_2"=>"", "city"=>"**city**", "state"=>"CA", "zip"=>"**zip code**", "provence"=>"", "country"=>"United States", "has_shipping"=>"true"}, "commit"=>"Calculate Shipping"}
  User Load (0.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ?  ORDER BY "users"."id" ASC LIMIT 1  [["id", 1]]
  User Load (0.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", 1]]
  Order Load (0.1ms)  SELECT  "orders".* FROM "orders" WHERE "orders"."id" = ? LIMIT 1  [["id", …
Run Code Online (Sandbox Code Playgroud)

ajax ruby-on-rails devise

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

无法使用 Rails 5.2、AWS S3 和 ActiveStorage 自动加载常量 ActiveStorage::Blob::Analyzable 错误

我已经和这个家伙战斗了一段时间,并在它上面做了所有的谷歌搜索(这里这里,以及许多同样无益的其他人),但无济于事。

官方错误是这样的,在我的 create 方法的第一行调用:

无法自动加载常量 ActiveStorage::Blob::Analyzable,需要 /Users/lizbayardelle/.rvm/gems/ruby-2.5.0/gems/activestorage-5.2.1/app/models/active_storage/blob/analyzable.rb 来定义它

我正在创建一个blog模型, whichhas_one_attached :pdf和 one :image,都通过 ActiveStorage。这些关系都在blog模型中:

class Blog < ApplicationRecord
  belongs_to :user
  has_one_attached :image
  has_one_attached :pdf
end
Run Code Online (Sandbox Code Playgroud)

我的控制器blogs#create模型在这里:

  def create
    @blog = Blog.new(blog_params)
    @blog.user_id = current_user.id
    if @blog.published
      @blog.published_on = DateTime.current
    end

    respond_to do |format|
      if @blog.save
        @blog.image.attach(params[:image])
        @blog.pdf.attach(params[:pdf])
        format.html { redirect_to @blog, notice: 'Blog was successfully created.' }
        format.json { render :show, status: :created, location: @blog }
      else …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails rails-activerecord

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

仅使用 Bootstrap 移动设备上的奇怪灰色按钮背景

我有一个如下所示的导航:

    <nav class="text-center">
      <button class="btn nav-button color-house" type="button"><%= link_to "House", home_house_path, class: "color-house" %></button>
      <button class="btn nav-button color-spouse" type="button"><%= link_to "Spouse", home_spouse_path, class: "color-spouse" %></button>
      <button class="btn nav-button color-kids" type="button"><%= link_to "Kids", home_kids_path, class: "color-kids" %></button>
      <button class="btn nav-button color-neutral" type="button"><%= link_to "Blog", blogs_path %></button>
    </nav>
Run Code Online (Sandbox Code Playgroud)

在计算机上运行良好: 在此处输入图片说明

但是由于某些奇怪的原因在移动设备上有一个奇怪的灰色背景: 在此处输入图片说明

奇怪的是,如果我尝试使用 chrome Inspector 的移动模拟器,它看起来完全没问题……图像仅在实际手机上显示为不需要的灰色。

到Heroku的网站链接是在这里如果你想看到实际的东西。

我觉得这必须是某种 Bootstrap 4 的东西,因为我从来没有在没有它的网站上经历过这种行为。

我试过background-color: white !importantbtnnav-button,但无济于事。我目前唯一的自定义 CSS 是这样的:

$color-house: #84C99A;
$color-spouse: #313E50;
$color-kids: #EFB0A1;
$color-neutral: #B7AD99;
$color-black: #26010C; …
Run Code Online (Sandbox Code Playgroud)

css bootstrap-4

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