class Article < ActiveRecord::Base
mount_uploader :img, ShareUploader
default_scope -> {where( :status => 0 )}
end
在 Article 中为了省事用了 default_scope,当 status=1 时,修改 img 图片字段报
---------------------
Article Load (7.4ms) SELECT `articles`.* FROM `articles` ORDER BY `articles`.`id` ASC LIMIT 1
(5.1ms) BEGIN
Article Load (5.6ms) SELECT `articles`.* FROM `articles` WHERE `articles`.`status` = 0 AND `articles`.`id` = 1 LIMIT 1
(5.0ms) ROLLBACK
Completed 404 Not Found in 200ms (ActiveRecord: 124.4ms)
ActiveRecord::RecordNotFound (Couldn't find Article with 'id'=1 [WHERE `articles`.`status` = ?]):
app/controllers/admins/article_controller.rb:58:in `up_article'
Rendered /home/haonan/.rvm/gems/ruby-2.1.4/gems/actionpack-4.2.5.2/lib/action_dispatch/middleware/templates/rescues/_source.erb (5.8ms)
Rendered /home/haonan/.rvm/gems/ruby-2.1.4/gems/actionpack-4.2.5.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.8ms)
Rendered /home/haonan/.rvm/gems/ruby-2.1.4/gems/actionpack-4.2.5.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms)
Rendered /home/haonan/.rvm/gems/ruby-2.1.4/gems/actionpack-4.2.5.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (19.4ms)
Rendered /home/haonan/.rvm/gems/ruby-2.1.4/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (0.5ms)
Rendered /home/haonan/.rvm/gems/ruby-2.1.4/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.2ms)
Rendered /home/haonan/.rvm/gems/ruby-2.1.4/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.3ms)
Rendered /home/haonan/.rvm/gems/ruby-2.1.4/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.7ms)
Rendered /home/haonan/.rvm/gems/ruby-2.1.4/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (15.1ms)
Rendered /home/haonan/.rvm/gems/ruby-2.1.4/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (0.2ms)
Rendered /home/haonan/.rvm/gems/ruby-2.1.4/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.3ms)
Rendered /home/haonan/.rvm/gems/ruby-2.1.4/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (29.2ms)
下面是执行的代码
puts "---------------------"
a = Article.unscoped.where(:id=>params[:id],:status=>article.status).unscoped.first#.update(:status=>article.status,:img=>params[:img])
a.img = params[:img]
a.save
不知道是怎么回事,明明使用了 unscoped,但是还是一直报找不到的错误,请教大家了