การใช้งานคำสั่ง before_filter

  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.

ปกติผมใช้ before_filter ใน controller แบบนี้

before_filter filter, :except => [ :unfilter_action, :another_unfilter_action ]

นั่นคือผมจะบังคับให้ทุก action ใน controller นี้ต้องวิ่งผ่าน filter ก่อนที่จะไปทำอะไรก็ตามใน action ยิ่งถ้าผมใส่ before_filter ใน application.rb ไม่ว่าจะเรียก controller ไหน action ใด มันก็จะเรียก filter ไปซะทุกครั้ง ยกเว้น action ที่ผมใส่ใน except เท่านั้นที่ไม่ถูกเรียก

ปัญหาคือ ถ้าผมใส่ before_filter ใน application แล้วต้องการ except เฉพาะ :controller => "user", :action => "index" แต่ action => "index" ใน controller อื่นๆ ให้เรียกผ่าน filter ก่อน แบบนี้ต้องประกาศ befor_filter อย่างไรครับ

รบกวนผู้รู้ด้วยครับ

http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods...

  class ApplicationController < ActionController::Base
    before_filter :authenticate
    around_filter :catch_exceptions
  end
 
  class WeblogController < ApplicationController
    # Will run the :authenticate and :catch_exceptions filters.
  end
 
  class SignupController < ApplicationController
    # Skip :authenticate, run :catch_exceptions.
    skip_before_filter :authenticate
  end
 
  class ProjectsController < ApplicationController
    # Skip :catch_exceptions, run :authenticate.
    skip_filter :catch_exceptions
  end
 
  class ClientsController < ApplicationController
    # Skip :catch_exceptions and :authenticate unless action is index.
    skip_filter :catch_exceptions, :authenticate, :except => :index
  end
apirak's picture

เยี่ยมไปเลย ขอบคุณครับ

Apirak

ย้าย Codenone

ประกาศย้าย Codenone ไปใช้ Forum ของ Blognone แทนครับ ตามไปตั้งกระทู้ต่อได้ที่ Codenone Forum (รายละเอียดอ่านจากกระทู้ ย้าย Codenone ไปรวมกับ Blognone)

กระทู้เก่าๆ จะย้ายตามไปในภายหลัง ตอนนี้ปิดการโพสต์กระทู้ไว้ เหลือไว้เฉพาะอ้างอิงเท่านั้น