# Render a file

**URL:** <https://www.ruby-forum.com/t/render-a-file/174067>\
**Category:** Rails\
**Created:** [August 20, 2009, 9:45am UTC](https://www.ruby-forum.com/t/render-a-file/174067 "2009-08-20T09:45:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9dc877/32.png) [@mahesh](https://www.ruby-forum.com/u/mahesh)\
**Post date:** [August 20, 2009, 9:45am UTC](https://www.ruby-forum.com/t/render-a-file/174067/1 "2009-08-20T09:45:29Z")

</div>

Im trying render a file 404 from public folder Is possible to render a  
file from ruby code i have a separate code in the lib file.i got a  
error like undefined method `render’ for AdminController:Class

---

<div class="post-metadata">

**Author:** ![mahesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9dc877/32.png) [@mahesh](https://www.ruby-forum.com/u/mahesh)\
**Post date:** [August 20, 2009, 9:58am UTC](https://www.ruby-forum.com/t/render-a-file/174067/2 "2009-08-20T09:58:57Z")

</div>

On Aug 20, 5:09 am, mahesh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Im trying render a file 404 from public folder Is possible to render a  
> file from ruby code i have a separate code in the lib file.i got a  
> error like undefined method `render’ for AdminController:Class

Well other than saying that you are calling render from somewhere that  
you shouldn’t there’s not a lot more to be said without seeing what  
you have done.

Fred

---

<div class="post-metadata">

**Author:** ![mahesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9dc877/32.png) [@mahesh](https://www.ruby-forum.com/u/mahesh)\
**Post date:** [August 20, 2009, 10:26am UTC](https://www.ruby-forum.com/t/render-a-file/174067/3 "2009-08-20T10:26:28Z")

</div>

ok This my module which in lib folder  
module Rakelimit  
def self.included(controller)

```
    controller.extend(ClassMethods)

   end

   module ClassMethods

    def acts_as_rakelimit
         ip = request.remote_ip
        puts ip = local_ip
       minute= (Time.now.to_i / 60).to_i
        checks = Ipcheck.find(:first, :conditions =>[ "ipaddress = ?

```

and time\_min =?", ip,minute] )  
puts checks.inspect  
if checks == nil

Ipcheck.create!(:ipaddress=\>ip,:time\_min=\>minute,:ip\_count=\>1)  
else  
checks.increment(:ip\_count,1).save  
if checks.ip\_count \>3

```
                render_404

       end
        end
    end

     def render_404
           render :file =>"#{RAILS_ROOT}/public/404.html", :status 

```

=\>  
“404 Not Found”

```
         return false
     end

```

it’s for susbend the process when the person trying more then 3 time if  
it  
increased more then 3 then i would like render 404 error

On Thu, Aug 20, 2009 at 1:28 PM, Frederick C. \<

---

<div class="post-metadata">

**Author:** ![mahesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9dc877/32.png) [@mahesh](https://www.ruby-forum.com/u/mahesh)\
**Post date:** [August 20, 2009, 10:45am UTC](https://www.ruby-forum.com/t/render-a-file/174067/4 "2009-08-20T10:45:13Z")

</div>

ok what will be the solution for me

On Thu, Aug 20, 2009 at 2:01 PM, Frederick C. \<

---

<div class="post-metadata">

**Author:** ![mahesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9dc877/32.png) [@mahesh](https://www.ruby-forum.com/u/mahesh)\
**Post date:** [August 20, 2009, 10:32am UTC](https://www.ruby-forum.com/t/render-a-file/174067/5 "2009-08-20T10:32:20Z")

</div>

On Aug 20, 9:26 am, mahesh s [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> def render_404
> render :file =>"#{RAILS_ROOT}/public/404.html", :status =>
> 
> ```
> 
> “404 Not Found”
> 
> ```
> return false
> end
> 
> ```
> 
> it’s for susbend the process when the person trying more then 3 time if it  
> increased more then 3 then i would like render 404 error

These shouldn’t be class methods. This is all about dealing with an  
individual request, which only makes sense in the context of an  
instance method

Fred
