#1 楼 @blacktulip 听起来很高端的样子,我想想哈……
#8 楼 @chenge #6 楼 @themorecolor #4 楼 @Rei 发现我的这个项目竟然内置了 gem 'responders',不过我又单独在 gemfile 里声明了,免得下次升级时就找不到它了…… 决定用 respond_with 版本,因为我看到个帖子respond_to Without All the Pain,感觉的确不错
#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
#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 楼 @hz_qiuyuanxin #2 楼 @michael_roshen #3 楼 @gothic #4 楼 @JeskTop 好了,谢谢各位:)
请问,如果我在一个页面使用多个 textarea,也就是需要多个富文本编辑器,这时候会显示很奇怪的现象,怎么办?
#21 楼 @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 的话,这个文件就不会为空。
#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
那一天才备份一次,我得明天才能检查结果哦……
结果是:
所以:
#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,没带端口的。我这个会少什么吗?
#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'
/usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/spec_set.rb:85:in `map!'
/usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/spec_set.rb:85:in `materialize'
/usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/definition.rb:132:in `specs'
/usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/definition.rb:177:in `specs_for'
/usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/definition.rb:166:in `requested_specs'
/usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/environment.rb:18:in `requested_specs'
/usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/runtime.rb:13:in `setup'
/usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler.rb:121:in `setup'
/usr/local/rvm/gems/ruby-2.1.2/gems/bundler-1.7.6/lib/bundler/setup.rb:17:in `<top (required)>'
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `require'
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:144:in `require'
/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'
/usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/lib/phusion_passenger/loader_shared_helpers.rb:366:in `running_bundler'
/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'
/usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:100:in `preload_app'
/usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:158:in `<module:App>'
/usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
/usr/local/rvm/gems/ruby-2.1.2/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:28:in `<main>'</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.