Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8738181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:41:07+00:00 2026-06-13T10:41:07+00:00

I am trying to use a before filter to prevent non-approved users from accessing

  • 0

I am trying to use a before filter to prevent non-approved users from accessing a page.

To check for non-approved users, I have a method defined in an .rb file, in the /lib folder (I have several methods there that I was in various controllers and views). The method is check_user_for_current_approval(user_id).

In my controller, I tried the following variations (note that I am using RubyMine as an IDE, and it did not give me an indication that I had a syntax error):

before_filter(:only => [:new]) do |c|
    c.check_user_for_current_approval current_user.id
end

Which gave me the following error message:

NoMethodError in PaymentsController#new

private method `check_user_for_current_approval' called for #<PaymentsController:0x007ff06784f148>

The following syntax:

before_filter(:only => [:new]) do |c|
    c.send (:check_user_for_current_approval, current_user.id)
end

Produces this error:

SyntaxError in PaymentsController#new

/app/controllers/payments_controller.rb:9: syntax error, unexpected ',', expecting ')'
c.send (:check_user_for_current_approval, current_user.id)
                                         ^
/app/controllers/payments_controller.rb:9: syntax error, unexpected ')', expecting keyword_end
/app/controllers/payments_controller.rb:130: syntax error, unexpected $end, expecting keyword_end

Using this syntax:

before_filter(:only => [:new]) { check_user_for_current_approval(current_user.id) }

takes me straight to the page (filter has no effect). The different statements came from answers that I’ve seen on StackOverflow.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:41:08+00:00Added an answer on June 13, 2026 at 10:41 am

    Use your first method, but make check_user_for_current_approval public.

    Also:

    I think the shared before_filter would be better suited in the Application Controller, rather than in a lib-file.
    That would make it accessible to all controllers that extend the Application Controller, which normally all other controllers do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use a class as a before filter for multiple controllers. Because
I'm trying to use a list of clients that have been created from my
I'm trying to use NSArray's filteredArrayUsingPredicate: method to filter an array of core data
I'm trying to learn how to use the :before and :after pseudo elements. I'm
I'm trying to use cURL with the proxy setting, which was working fine before
What type of iPhone application file should I use? Before, I was trying to
i'm trying use facebook API to upload photo in my fan page. I downloaded
I am trying use gem tire to search in my application. I have tables
I was trying use a set of filter functions to run the appropriate routine,
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.