• #1 楼 @blacktulip 听起来很高端的样子,我想想哈……

  • #8 楼 @chenge #6 楼 @themorecolor #4 楼 @Rei 发现我的这个项目竟然内置了 gem 'responders',不过我又单独在 gemfile 里声明了,免得下次升级时就找不到它了…… 决定用 respond_with 版本,因为我看到个帖子respond_to Without All the Pain,感觉的确不错

  • #8 楼 @chenge 有些地方简短了,有些也多了啊!比如:

    # 旧
    def index
        @projects = Project.all
    end
    
    # 新
    def index
        @tries = Try.all
        # 非要这样声明结果么?
        respond_with(@tries)
    end
    

    话说,到底哪种才是最好的用法?

  • #6 楼 @themorecolor #8 楼 @chenge

    我以为这个 respond_with 是新式用法,可是昨天查官方 Guide 也没看到,要不我还是用回之前的那款 respond_to 好了……

    respond_to do |format|
          format.html { redirect_to projects_url, notice: 'Project was successfully destroyed.' }
          format.json { head :no_content }
        end
    
  • #4 楼 @Rei 我明明记得我那旧项目一开始就是用的 Rails4.2.0…… 本来我用 4.1.8 写了一部分,后来我看到 4.2 出了,就直接 rails new project,用的就是 4.2,没升级…… 哎呀呀,真的很诡异……

  • #1 楼 @Rei 尼玛,好吓人!我在这个项目生成的 scaffold 得到的 controller 依然是这些 respond_with!

    class TriesController < ApplicationController
      before_action :set_try, only: [:show, :edit, :update, :destroy]
    
      respond_to :html
    
      def index
        @tries = Try.all
        respond_with(@tries)
      end
    
      def show
        respond_with(@try)
      end
    
      def new
        @try = Try.new
        respond_with(@try)
      end
    
      def edit
      end
    
      def create
        @try = Try.new(try_params)
        @try.save
        respond_with(@try)
      end
    
      def update
        @try.update(try_params)
        respond_with(@try)
      end
    
      def destroy
        @try.destroy
        respond_with(@try)
      end
    
      private
        def set_try
          @try = Try.find(params[:id])
        end
    
        def try_params
          params.require(:try).permit(:try1, :try2)
        end
    end
    
    
  • #1 楼 @Rei 我的妈呀!太神奇了!这下我也不明白了!我刚刚 rails new 新建了个项目,生成的 scaffold 也是

    class ProjectsController < ApplicationController
      before_action :set_project, only: [:show, :edit, :update, :destroy]
    
      # GET /projects
      # GET /projects.json
      def index
        @projects = Project.all
      end
    
      # GET /projects/1
      # GET /projects/1.json
      def show
      end
    
      # GET /projects/new
      def new
        @project = Project.new
      end
    
      # GET /projects/1/edit
      def edit
      end
    
      # POST /projects
      # POST /projects.json
      def create
        @project = Project.new(project_params)
    
        respond_to do |format|
          if @project.save
            format.html { redirect_to @project, notice: 'Project was successfully created.' }
            format.json { render :show, status: :created, location: @project }
          else
            format.html { render :new }
            format.json { render json: @project.errors, status: :unprocessable_entity }
          end
        end
      end
    
      # PATCH/PUT /projects/1
      # PATCH/PUT /projects/1.json
      def update
        respond_to do |format|
          if @project.update(project_params)
            format.html { redirect_to @project, notice: 'Project was successfully updated.' }
            format.json { render :show, status: :ok, location: @project }
          else
            format.html { render :edit }
            format.json { render json: @project.errors, status: :unprocessable_entity }
          end
        end
      end
    
      # DELETE /projects/1
      # DELETE /projects/1.json
      def destroy
        @project.destroy
        respond_to do |format|
          format.html { redirect_to projects_url, notice: 'Project was successfully destroyed.' }
          format.json { head :no_content }
        end
      end
    
      private
        # Use callbacks to share common setup or constraints between actions.
        def set_project
          @project = Project.find(params[:id])
        end
    
        # Never trust parameters from the scary internet, only allow the white list through.
        def project_params
          params.require(:project).permit(:backgroud, :result)
        end
    end
    
    

    不行,我要在我刚才那旧项目新建个 scaffold 试试,这简直灵异事件了!!!哪来的代码?!!!

  • #1 楼 @Rei 啊?那我的项目代码哪来的?我新建个项目试试……我明明都是用 scaffold 生成的啊!

  • 开源 Tower 的编辑器 Simditor at 2015年01月14日

    请问,如果我在一个页面使用多个 textarea,也就是需要多个富文本编辑器,这时候会显示很奇怪的现象,怎么办?

  • #21 楼 @liujianhei 哦,谢谢,我消化一下……

  • #17 楼 @liujianhei

    #1 楼 @Rei 我发现一个问题,手动执行 backup perform --trigger a_project 与 cron 自动执行输出结果差别:

    [2015/01/12 23:57:32][warn]   Pipeline STDERR Messages:
    [2015/01/12 23:57:32][warn]   (Note: may be interleaved if multiple commands returned error messages)
    [2015/01/12 23:57:32][warn] 
    [2015/01/12 23:57:32][warn]   Warning: Using a password on the command line interface can be insecure.
    

    手动比 cron 执行多了一个密码的警句,看来的确是用户权限和密码问题。 但我手动时也没有附带密码啊,密码应该已经写在 backup 文件里的了啊! 这应该修改哪里呢?

  • #17 楼 @liujianhei 恩,是这样,它执行了,也生成了相应的文件,就是文件内容为空,很奇怪。手动 backup 的话,这个文件就不会为空。

    #18 楼 @hanluner 还是很感激啊,各种解决的可能方案都很重要啊!

  • #11 楼 @hanluner 是 centos,但你说的 tab 占位符,指的是哪个文件里的?

  • #9 楼 @liujianhei 唉,没看到什么有用的信息。还得得到空白的结果……

    [2015/01/09 07:50:01][info] Performing Backup for 'xxx周报系统备份生成 (a_project)'!
    [2015/01/09 07:50:01][info] [ backup 4.1.5 : ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux] ]
    [2015/01/09 07:50:01][info] Database::MySQL Started...
    [2015/01/09 07:50:01][info] Using Compressor::Gzip for compression.
    [2015/01/09 07:50:01][info]   Command: '/usr/bin/gzip'
    [2015/01/09 07:50:01][info]   Ext: '.gz'
    [2015/01/09 07:50:01][info] Database::MySQL Finished!
    [2015/01/09 07:50:01][info] Packaging the backup files...
    [2015/01/09 07:50:02][info] Packaging Complete!
    [2015/01/09 07:50:02][info] Cleaning up the temporary files...
    [2015/01/09 07:50:02][info] Storage::Local Started...
    [2015/01/09 07:50:02][info] Storing '/root/backups/a_project/2015.01.09.07.50.01/a_project.tar'...
    [2015/01/09 07:50:02][info] Cycling Started...
    [2015/01/09 07:50:02][info] Removing backup package dated 2014.12.28.11.00.02...
    [2015/01/09 07:50:02][info] Storage::Local Finished!
    [2015/01/09 07:50:02][info] Cleaning up the package files...
    [2015/01/10 07:50:02][info] Performing Backup for 'xxx周报系统备份生成 (a_project)'!
    [2015/01/10 07:50:02][info] [ backup 4.1.5 : ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux] ]
    [2015/01/10 07:50:02][info] Database::MySQL Started...
    [2015/01/10 07:50:02][info] Using Compressor::Gzip for compression.
    [2015/01/10 07:50:02][info]   Command: '/usr/bin/gzip'
    [2015/01/10 07:50:02][info]   Ext: '.gz'
    [2015/01/10 07:50:02][info] Database::MySQL Finished!
    [2015/01/10 07:50:02][info] Packaging the backup files...
    [2015/01/10 07:50:02][info] Packaging Complete!
    [2015/01/10 07:50:02][info] Cleaning up the temporary files...
    [2015/01/10 07:50:02][info] Storage::Local Started...
    [2015/01/10 07:50:02][info] Storing '/root/backups/a_project/2015.01.10.07.50.02/a_project.tar'...
    [2015/01/10 07:50:02][info] Cycling Started...
    [2015/01/10 07:50:02][info] Removing backup package dated 2014.12.30.11.00.02...
    [2015/01/10 07:50:02][info] Storage::Local Finished!
    [2015/01/10 07:50:02][info] Cleaning up the package files...
    [2015/01/11 07:50:02][info] Performing Backup for 'xxx周报系统备份生成 (a_project)'!
    [2015/01/11 07:50:02][info] [ backup 4.1.5 : ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux] ]
    [2015/01/11 07:50:02][info] Database::MySQL Started...
    [2015/01/11 07:50:02][info] Using Compressor::Gzip for compression.
    [2015/01/11 07:50:02][info]   Command: '/usr/bin/gzip'
    [2015/01/11 07:50:02][info]   Ext: '.gz'
    [2015/01/11 07:50:02][info] Database::MySQL Finished!
    [2015/01/11 07:50:02][info] Packaging the backup files...
    [2015/01/11 07:50:02][info] Packaging Complete!
    [2015/01/11 07:50:02][info] Cleaning up the temporary files...
    [2015/01/11 07:50:02][info] Storage::Local Started...
    [2015/01/11 07:50:02][info] Storing '/root/backups/a_project/2015.01.11.07.50.02/a_project.tar'...
    "/tmp/cron.log" 48L, 3162C
    
    
    
  • #7 楼 @liujianhei 噢,这是 UTC 时间吧?还得等……我今天折腾不下去了,各种 bug 各种坑……下周再看好了…… 谢谢啊……周末愉快啊……

  • #5 楼 @liujianhei 哭……看不懂你这“50 15 * * * ”指的是几点?是不是已经过了?

  • #2 楼 @liujianhei 你意思是在 whenever 的设置里改吗? 改成这样吗?

    every 1.day, :at => '19:00' do
      command "backup perform --trigger a_project"
      set :output, "/tmp/cron.log"
    end
    

    那一天才备份一次,我得明天才能检查结果哦……

  • #1 楼 @Rei 没明白你的意思耶…… 我之前的设想是:

    1. 对于整个服务器,设置一个非 root 的超级用户,用来部署。
    2. 对于 mysql,设置一个非 root 的超级用户,用来项目交互。

    结果是:

    1. 对于整个服务器,我创建的用户总是受到各种限制(sudoer 没成功吧),我觉得麻烦,就一直用 root 了。
    2. 对于 mysql,超级用户创建成功,所以我一直用 bibi 这个用户名。

    所以:

    1. 你说的切换 root 用户,指的是服务器的用户,还是 mysql 的用户?
    2. crontab 静默退出,那它为什么能每天生成一个表面正确的备份的? 比如,它会在目录下生成 2015.01.08.19.29.54/a_project.tar, 解压之后,里面是 weekly_report/databases/MySQL.sql.gz,再解压得到一个 MySQL.sql。 只是手动备份时,里面是有内容的。自动备份时,里面是空白的。但它生成了这个文件耶……
    3. 你说的退出再登录,是指退出什么啊?我平时用 ssh [email protected],直接登录(设置了 ssh key),不用密码的。 crontab 在服务器本身,backup 文件里有 mysql 密码,它还需要什么啊?
  • #11 楼 @blacktulip 谢谢啦:)

  • #11 楼 @blacktulip 哦,那我改回 80 算了。我以为新开个端口会更好……

  • #9 楼 @blacktulip 因为 80 好像有别的很多服务在用……要不我改回 80 试试?

  • #7 楼 @blacktulip 我监听的是 8888 端口,但我希望我输入的时候只输入 week.a.com 就能跳到我的这个 8888 端口,不可以的么?

  • #5 楼 @blacktulip 不啊,IP 的话还是要用端口啊……

  • #3 楼 @blacktulip 重启过了。要不我再试一次看看。

  • #1 楼 @blacktulip 他们说已经把“week.a.com 指向了这个 IP , xxx.xxx.xxx.xxx,没带端口的。我这个会少什么吗?

  • #11 楼 @appell 哦,原来可以对应不同版本,我明天再试试。今天折腾崩溃了。谢谢哦:)

  • #11 楼 @appell 下午设置过 passenger_root, passenger_ruby,还是不行,貌似已经安装的 passenger 有它能对应的 ruby 版本? 现在感觉问题好像又出在 gemset 上了,明天再接着折腾……哎呀呀,莫名其妙啊……

  • #5 楼 @flowerwrong 额,装完了新 passenger,还是没解决。

  • #5 楼 @flowerwrong 看蒙我了 …… 我看了看 nginx 的 error 日志,怀疑是不是因为我上个项目用的是 ruby-2.1.2,这个项目用的是 ruby-2.2.0, (而且我连 rvm 都升级了),然后之前的 passenger 装在 rvm/gems/ruby-2.1.2/gems 里,所以它找不到要用的 passenger……

    要不我再装个 passenger 看看……

    [ 2015-01-05 02:56:09.7061 29783/7f54445d6700 Pool2/Implementation.cpp:287 ]: Could not spawn process for application /var/www/b_project/current: An error occured while starting up the preloader.
      Error ID: 9ad6e2b0
      Error details saved to: /tmp/passenger-error-3qukEK.html
      Message from application: <p>It looks like Bundler could not find a gem. Maybe you didn't install all the gems that this application needs. To install your gems, please run:</p>
    
      <pre class="commands">bundle install</pre>
    
    <p>If that didn't work, then maybe the problem is that your gems are installed to <code>//.rvm/gems</code>, while at the same time you set <code>PassengerRuby</code> (Apache) or <code>passenger_ruby</code> (Nginx) to <code>/usr/local/rvm/gems/ruby-2.1.2/wrappers/ruby</code>. Because of the latter, RVM does not load gems from the home directory.</p>
    
    <p>To make RVM load gems from the home directory, you need to set <code>PassengerRuby</code>/<code>passenger_ruby</code> to an RVM wrapper script inside the home directory:</p>
    
    <ol>
      <li>Login as nobody.</li>
      <li>Enable RVM mixed mode by running:
          <pre class="commands">rvm user gemsets</pre></li>
      <li>Run this to find out what to set <code>PassengerRuby</code>/<code>passenger_ruby</code> to:
          <pre class="commands">/usr/local/rvm/gems/ruby-2.1.2/wrappers/ruby \
    /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/bin/passenger-config --detect-ruby</pre></li>
    </ol>
    
    <p>If that didn't help either, then maybe your application is being run under a different environment than it's supposed to. Please check the following:</p>
    
    <ol>
      <li>Is this app supposed to be run as the <code>nobody</code> user?</li>
      <li>Is this app being run on the correct Ruby interpreter? Below you will
          see which Ruby interpreter Phusion Passenger attempted to use.</li>
      <li>Please check whether the correct RVM gemset is being used.</li>
      <li>Sometimes, RVM gemsets may be broken.
          <a href="https://github.com/phusion/passenger/wiki/Resetting-RVM-gemsets">Try resetting them.</a></li>
    </ol>
    
    <p>-------- The exception is as follows: -------</p>
    Could not find rake-10.4.2 in any of the sources (Bundler::GemNotFound)
    <pre>  /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/spec_set.rb:92:in `block in materialize&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/spec_set.rb:85:in `map!&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/spec_set.rb:85:in `materialize&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/definition.rb:132:in `specs&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/definition.rb:177:in `specs_for&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/definition.rb:166:in `requested_specs&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/environment.rb:18:in `requested_specs&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/runtime.rb:13:in `setup&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler.rb:121:in `setup&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/setup.rb:17:in `&lt;top (required)&gt;&#39;
      /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `require&#39;
      /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require&#39;
      /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:144:in `require&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/lib/phusion_passenger/loader_shared_helpers.rb:263:in `block in run_load_path_setup_code&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/lib/phusion_passenger/loader_shared_helpers.rb:366:in `running_bundler&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/lib/phusion_passenger/loader_shared_helpers.rb:261:in `run_load_path_setup_code&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:100:in `preload_app&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:158:in `&lt;module:App&gt;&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:29:in `&lt;module:PhusionPassenger&gt;&#39;
      /usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:28:in `&lt;main&gt;&#39;</pre>
    
    
    [ 2015-01-05 02:56:09.7123 29783/7f54421a7700 agents/HelperAgent/RequestHandler.h:2306 ]: [Client 41] Cannot checkout session because a spawning error occurred. The identifier of the error is 9ad6e2b0. Please see earlier logs for details about the error.