# Undefined method error

**URL:** <https://www.ruby-forum.com/t/undefined-method-error/186077>\
**Category:** Rails\
**Created:** [March 31, 2010, 10:00am UTC](https://www.ruby-forum.com/t/undefined-method-error/186077 "2010-03-31T10:00:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gautam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ab992/32.png) [@gautam](https://www.ruby-forum.com/u/gautam)\
**Post date:** [March 31, 2010, 10:00am UTC](https://www.ruby-forum.com/t/undefined-method-error/186077/1 "2010-03-31T10:00:58Z")

</div>

I am getting the following error when trying to link a method in a  
view so that it can be called on that very object(id).

undefined method `abc\_notice\_path’ for #ActionView::Base:0xed65220

Extracted source (around line #25):

22: \<%= link\_to ‘Edit’, edit\_notice\_path(@notice) %\> |  
23: \<%= link\_to ‘Back’, notices\_path %\>  
24: |  
25: \<%= link\_to ‘Save’, abc\_notice\_path(@notice) %\>

Here is the code for my method.

def abc  
@notice = Notice.find(params[:id])  
#f = File.new("#{RAILS\_ROOT}/public/jar/notice.txt",“w”)  
#f.write @notice.title  
#f.write @notice.body  
#f.write @notice.user\_name  
#f.close  
#send\_file("#{RAILS\_ROOT}/public/jar/notice.txt")  
end

I wonder why i am getting this error. This method is defined in a  
controller which was generated through scaffolding and other functions  
that were created are working fine.  
Please help me. I am a novice to rails. Any help will be highly  
appreciated.

---

<div class="post-metadata">

**Author:** ![gautam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ab992/32.png) [@gautam](https://www.ruby-forum.com/u/gautam)\
**Post date:** [March 31, 2010, 2:38pm UTC](https://www.ruby-forum.com/t/undefined-method-error/186077/2 "2010-03-31T14:38:24Z")

</div>

Gautam wrote:

> I am getting the following error when trying to link a method in a  
> view so that it can be called on that very object(id).
> 
> undefined method `abc\_notice\_path’ for #ActionView::Base:0xed65220
> 
> Extracted source (around line #25):
> 
> 22: \<%= link\_to ‘Edit’, edit\_notice\_path(@notice) %\> |  
> 23: \<%= link\_to ‘Back’, notices\_path %\>  
> 24: |  
> 25: \<%= link\_to ‘Save’, abc\_notice\_path(@notice) %\>
> 
> Here is the code for my method.
> 
> def abc  
> @notice = Notice.find(params[:id])  
> #f = File.new("#{RAILS\_ROOT}/public/jar/notice.txt",“w”)  
> #f.write @notice.title  
> #f.write @notice.body  
> #f.write @notice.user\_name  
> #f.close  
> #send\_file("#{RAILS\_ROOT}/public/jar/notice.txt")  
> end
> 
> I wonder why i am getting this error. This method is defined in a  
> controller which was generated through scaffolding and other functions  
> that were created are working fine.  
> Please help me. I am a novice to rails. Any help will be highly  
> appreciated.

Hi Gautam,

Please check your routes.rb first, I think u forget to specify the name  
of the action in route.

---

<div class="post-metadata">

**Author:** ![gautam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ab992/32.png) [@gautam](https://www.ruby-forum.com/u/gautam)\
**Post date:** [March 31, 2010, 7:35pm UTC](https://www.ruby-forum.com/t/undefined-method-error/186077/3 "2010-03-31T19:35:18Z")

</div>

Gautam wrote:

> Thanks for your kind reply.  
> Here is the code of my routes.rb file  
> Please suggest corrections, if any…
> 
> map.resources :notices  
> map.resources :users, :has\_many =\> :notices  
> map.resource :session
> 
> map.connect ‘:controller/:action/:id’  
> map.connect ‘:controller/:action/:id.:format’  
> map.connect ‘/notices/:id/:abc’, :controller =\> “notices”, :action  
> =\> “abc”
> 
> map.root :controller=\> ‘welcome’  
> map.signup ‘/signup’, :controller =\> ‘users’, :action =\> ‘new’  
> map.login ‘/login’, :controller =\> ‘sessions’, :action =\> ‘new’  
> map.logout ‘/logout’, :controller =\> ‘sessions’, :action =\>  
> ‘destroy’  
> map.create ‘/create’, :controller =\> ‘notices’, :action =\> ‘new’

try this out. Change

map.connect ‘/notices/:id/:abc’, :controller =\> “notices”, :action

> =\> “abc”

to

map.abc\_notice ‘/notices/:id/:abc’, :controller =\> “notices”, :action

> =\> “abc”

Then when you call abc\_notice\_path(4, ‘alphabet’)

Maybe that will help out.

---

<div class="post-metadata">

**Author:** ![gautam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ab992/32.png) [@gautam](https://www.ruby-forum.com/u/gautam)\
**Post date:** [March 31, 2010, 5:41pm UTC](https://www.ruby-forum.com/t/undefined-method-error/186077/4 "2010-03-31T17:41:44Z")

</div>

Thanks for your kind reply.  
Here is the code of my routes.rb file  
Please suggest corrections, if any…

map.resources :notices  
map.resources :users, :has\_many =\> :notices  
map.resource :session

map.connect ‘:controller/:action/:id’  
map.connect ‘:controller/:action/:id.:format’  
map.connect ‘/notices/:id/:abc’, :controller =\> “notices”, :action  
=\> “abc”

map.root :controller=\> ‘welcome’  
map.signup ‘/signup’, :controller =\> ‘users’, :action =\> ‘new’  
map.login ‘/login’, :controller =\> ‘sessions’, :action =\> ‘new’  
map.logout ‘/logout’, :controller =\> ‘sessions’, :action =\>  
‘destroy’  
map.create ‘/create’, :controller =\> ‘notices’, :action =\> ‘new’
