<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>tankzhuchen (朱晨)</title>
    <link>https://ruby-china.org/tankzhuchen</link>
    <description/>
    <language>en-us</language>
    <item>
      <title>已解决！cap 自动部署以后 carrierwave 上传图片功能失效</title>
      <description>&lt;p&gt;cap 自动部署以后上传图片报错&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;We're sorry, but something went wrong
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;进入远端查看报错日志，切换到 deploy 用户，输入&lt;code&gt;cd ~/项目名称/current&lt;/code&gt;进入到 rails 目录下&lt;/p&gt;

&lt;p&gt;输入&lt;code&gt;tail -f log/production.log&lt;/code&gt;查看实时报错记录，继续尝试上传看看报错详细&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Please set Qiniu's access_key and secret_key before authorize any tokens.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;提示需要先设置七牛的 ak 和 sk，但是我是用的 figaro 密码保护，已经在 yml 文件里设定好了，为什么还要我再去设定呢？&lt;/p&gt;

&lt;p&gt;最后查到是远端没有部署 figaro 密码保护的 yml 的相关文件，我是 cap 自动化部署的，首先在&lt;code&gt;config/deploy.rb&lt;/code&gt;的&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;append :linked_files, "config/database.yml", "config/secrets.yml"
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;加上 &lt;code&gt;"config/application.yml"&lt;/code&gt;然后保存，cap 部署&lt;/p&gt;

&lt;p&gt;然后再登录远端，切换到&lt;code&gt;cd /项目名称/shared/config&lt;/code&gt;并新建&lt;code&gt;touch application.yml&lt;/code&gt;然后编辑文档&lt;code&gt;nano application.yml&lt;/code&gt;把本地的 yml 文档里的密码设定复制到这里，然后保存。&lt;/p&gt;

&lt;p&gt;再次尝试上传，成功。&lt;/p&gt;

&lt;p&gt;参考链接：&lt;a href="https://segmentfault.com/q/1010000013740149?utm_source=tag-newest" rel="nofollow" target="_blank"&gt;https://segmentfault.com/q/1010000013740149?utm_source=tag-newest&lt;/a&gt;&lt;/p&gt;</description>
      <author>tankzhuchen</author>
      <pubDate>Tue, 09 Apr 2019 17:41:42 +0800</pubDate>
      <link>https://ruby-china.org/topics/38369</link>
      <guid>https://ruby-china.org/topics/38369</guid>
    </item>
    <item>
      <title>cap production deploy 自动化部署报错数据表格已经存在，该如何解？！</title>
      <description>&lt;p&gt;在本地测试都很正常，开始部署输入&lt;code&gt;cap production deploy&lt;/code&gt;报错&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Caused by:
SSHKit::Command::Failed: rake exit status: 1
rake stdout: == 20190408023032 AddImageToPost: migrating ===================================
-- add_column(:posts, :image, :string)
rake stderr: rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::DuplicateColumn: ERROR:  column "image" of relation "posts" already exists
: ALTER TABLE "posts" ADD "image" character varying
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;我删除了报错的 migrate，上传成功，但是功能丧失。&lt;/p&gt;

&lt;p&gt;我在网上寻找了答案，需要&lt;code&gt;rake db:drop&lt;/code&gt;&lt;code&gt;rake db:create&lt;/code&gt;&lt;code&gt;rake db:migrate&lt;/code&gt;,但是我这是远端的重复表格，所以我登录远端切换到 deploy 账户&lt;/p&gt;

&lt;p&gt;执行&lt;code&gt;cd ~/项目数据库名称/current&lt;/code&gt;切换到 current，输入&lt;code&gt;RAILS_ENV=production bundle exec rake db:drop DISABLE_DATABASE_ENVIRONMENT_CHECK=1&lt;/code&gt;报错
&lt;code&gt;ActiveRecord::StatementInvalid: PG::ObjectInUse: ERROR:  database "rails_recipes" is being accessed by other users
DETAIL:  There is 1 other session using the database.&lt;/code&gt;&lt;/p&gt;</description>
      <author>tankzhuchen</author>
      <pubDate>Mon, 08 Apr 2019 21:36:25 +0800</pubDate>
      <link>https://ruby-china.org/topics/38365</link>
      <guid>https://ruby-china.org/topics/38365</guid>
    </item>
    <item>
      <title>安装 ckeditor 富文档，报错：couldn't find file 'ckeditor/init' with type 'application/javascript'</title>
      <description>&lt;h2 id="终端机详细报错"&gt;终端机详细报错&lt;/h2&gt;
&lt;p&gt;ActionView::Template::Error (couldn't find file 'ckeditor/init' with type 'application/javascript')
Checked in these paths:
  /Users/zhuzhuchen/rails101/app/assets/config
  /Users/zhuzhuchen/rails101/app/assets/images
  /Users/zhuzhuchen/rails101/app/assets/javascripts
  /Users/zhuzhuchen/rails101/app/assets/stylesheets
  /Users/zhuzhuchen/rails101/vendor/assets/javascripts
  /Users/zhuzhuchen/rails101/vendor/assets/stylesheets
  /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/ckeditor-4.4.0/app/assets/images
  /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/ckeditor-4.4.0/app/assets/javascripts
  /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/ckeditor-4.4.0/app/assets/stylesheets
  /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/jquery-rails-4.3.3/vendor/assets/javascripts
  /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/coffee-rails-4.2.2/lib/assets/javascripts
  /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actioncable-5.0.7.1/lib/assets/compiled
  /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/turbolinks-source-5.2.0/lib/assets/javascripts
  /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/bootstrap-sass-3.3.7/assets/stylesheets
  /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/bootstrap-sass-3.3.7/assets/javascripts
  /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/bootstrap-sass-3.3.7/assets/fonts
 `/Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/bootstrap-sass-3.3.7/assets/images):
    4:     &lt;/p&gt;Rails101
    5:     &amp;lt;%= csrf_meta_tags %&amp;gt;
    6:
    7:     &amp;lt;%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %&amp;gt;
    8:     &amp;lt;%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %&amp;gt;
    9:   
   10:

&lt;p&gt;app/assets/javascripts/application.js:17
app/views/layouts/application.html.erb:7:in_app_views_layouts_application_html_erb__4471122603424365335_70331191397360'
  Rendering /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout
  Rendering /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
  Rendered /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (3.6ms)
  Rendering /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
  Rendered /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.5ms)
  Rendering /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
  Rendered /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.7ms)
  Rendered /Users/zhuzhuchen/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.7.1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (79.6ms)&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id="我做了以下事情"&gt;我做了以下事情&lt;/h2&gt;
&lt;p&gt;安装&lt;code&gt;gem 'ckeditor'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;在&lt;em&gt;app/assets/javascripts/application.js&lt;/em&gt;加入一行&lt;code&gt;//= require ckeditor/init&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;在&lt;em&gt;config/initializers/assets.rb&lt;/em&gt;加入一行&lt;code&gt;Rails.application.config.assets.precompile += %w( application.css application.js ckeditor/* )&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;修改了 new 的 simple_form&lt;code&gt;f.input :description, as: :ckeditor&lt;/code&gt;&lt;/p&gt;</description>
      <author>tankzhuchen</author>
      <pubDate>Thu, 28 Mar 2019 17:08:29 +0800</pubDate>
      <link>https://ruby-china.org/topics/38302</link>
      <guid>https://ruby-china.org/topics/38302</guid>
    </item>
  </channel>
</rss>
