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

  • Home
  • SEARCH
  • 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 166621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:07:47+00:00 2026-05-11T12:07:47+00:00

I try blocking Ip addresses in my app like this – lifeonrails.org . I

  • 0

I try blocking Ip addresses in my app like this – lifeonrails.org. I already have a module in /lib and model banned_ip.

Why I have this error below from views/banned_ips/index.html?

===My error:===

NoMethodError in Admin/banned_ips#index

Showing app/views/admin/banned_ips/index.html.erb where line #9 raised:

undefined method `banned?' for '127.0.0.1':String 

Extracted source (around line #9):

6:     <th>Last_ip</th> 7:     <th>Date</th> 8:   </tr> 9: <% if request.remote_ip.banned? == true %>banned<% else %>ok<% end %> 10: <% for banned_ip in @banned_ips %> 11:   <tr> 12:     <td><%=h banned_ip.first_ip %></td> 

===Module infrid.rb in /lib===

module Infrid   class IPAddress     include Comparable     def initialize(address)       @address = address     end     def split       @address.split(‘.‘).map {|s| s.to_i }     end     def <=>(other)       split <=> other.split     end     def to_s       @address     end   end end 

===Model banned_ip:===

class BannedIp < ActiveRecord::Base     @banned_ips # hash of ips and masks     validates_presence_of :first_ip, :message =>'first address is needed'     validates_presence_of :last_ip, :message =>'last address is needed'     validates_format_of :first_ip, :with => REG_IP, :message => 'is invalid (must be x.x.x.x where x is 0-255)', :if => Proc.new {|ar| !ar.first_ip.blank? }     validates_format_of :last_ip, :with => REG_IP, :message => 'is invalid (must be x.x.x.x where x is 0-255)', :if => Proc.new {|ar| !ar.last_ip.blank? }      def self.banned?(ip)       reload_banned_ips if @banned_ips.nil?       begin           ip = Infrid::IPAddress.new(ip)           @banned_ips.each { |b|             return true if ip.between?(b[0], b[1])           }       rescue           logger.info 'IP FORMAT ERROR'           return true       end       false     end     def self.banned_ips         reload_banned_ips if @banned_ips.nil?         @banned_ips.collect {|b| b[0].to_s + '..' + b[1].to_s }.join'\n'     end     #keeps a cache of all banned ip ranges     def self.reload_banned_ips       r = connection.select_all('select first_ip, last_ip from banned_ips')       if !r         @banned_ips=[]        end       @banned_ips = r.map {|item| [Infrid::IPAddress.new(item['first_ip']),Infrid::IPAddress.new(item['last_ip'])] }     end end 
  • 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. 2026-05-11T12:07:48+00:00Added an answer on May 11, 2026 at 12:07 pm

    Your problem is that you are trying to call banned? on a String, not on your BannedIp class. You have two solutions.

    1. Replace the code to check for banned ip with BannedIp.banned?(request.remote_ip)
    2. Patch in a method to the string class which calls the class method for you, which is in rails stype but less readable.

    Need this here. (bug prevents code block from working)

    class String   def banned?     BannedIp.banned?(self)   end end 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 78k
  • Answers 78k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Aaaand the answer just popped up on another web search.… May 11, 2026 at 3:38 pm
  • added an answer C99 way: #define FOO(...) printf(__VA_ARGS__) May 11, 2026 at 3:37 pm
  • added an answer It's hard to give a single all encompassing answer but… May 11, 2026 at 3:37 pm

Related Questions

I try blocking Ip addresses in my app like this - lifeonrails.org . I
I've kind of ran into an ugly snag. I developed a website for a
i'd like to prevent bots from hacking weak password-protected accounts. (e.g. this happend to
I have a library I'm writing unit tests for. The library is used by
I am writing a networked application in Java, to communicate between the client and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.