# MethodNotAllowed

**URL:** <https://www.ruby-forum.com/t/methodnotallowed/175797>\
**Category:** Rails\
**Created:** [September 19, 2009, 11:58pm UTC](https://www.ruby-forum.com/t/methodnotallowed/175797 "2009-09-19T23:58:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 19, 2009, 11:58pm UTC](https://www.ruby-forum.com/t/methodnotallowed/175797/1 "2009-09-19T23:58:19Z")

</div>

I am trying to develop an application that allows users to submit  
articles and add information about the references they used when  
citing facts. I have the sources broken down into types, such as  
books, periodicals, web-sites, etc as single table inheritance on the  
sources table. Routes are nested so that :articles, :has\_many  
=\> :sources When trying to edit a source, through the “edit” view, I  
get “ActionController::MethodNotAllowed - only get, put, and delete  
requests are allowed”. This should flow through the “update” action,  
which is a put method, and when I used rake routes on the command line  
it looks like it is routed correctly PUT /articles/:article\_id/  
sources/:id(.:format) {:controller =\> “sources”, :action =\>  
“update”}

My edit view contains the following code:

\<% form\_for :source, @source, :url =\> {:action =\> “update”} do |f| %\>

…form fields…

\<%= f.submit “Update” %\>

\<% end %\>

My controller has the following code:

def edit  
@source = @article.sources.find(params[:id])  
end

def update  
@source = @article.sources.find(params[:id])  
if @source.update\_attributes(params[:source])  
flash[:notice]…  
redirect\_to article\_path(@article) #@article is derived from  
before filter  
else  
render :action =\> “edit”  
end  
end

Any suggestions?

Thanks for you help!!!

-Kevin

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 21, 2009, 9:02am UTC](https://www.ruby-forum.com/t/methodnotallowed/175797/2 "2009-09-21T09:02:22Z")

</div>

removed\_email\_address@domain.invalid wrote:

> I am trying to develop an application that allows users to submit  
> articles and add information about the references they used when  
> citing facts. I have the sources broken down into types, such as  
> books, periodicals, web-sites, etc as single table inheritance on the  
> sources table. Routes are nested so that :articles, :has\_many  
> =\> :sources When trying to edit a source, through the “edit” view, I  
> get “ActionController::MethodNotAllowed - only get, put, and delete  
> requests are allowed”. This should flow through the “update” action,  
> which is a put method, and when I used rake routes on the command line  
> it looks like it is routed correctly PUT /articles/:article\_id/  
> sources/:id(.:format) {:controller =\> “sources”, :action =\>  
> “update”}

\<% form\_for([@article,@source]) do |f| %\>

…form fields…

\<%= f.submit “Update” %\>

\<% end %\>  
Try this

def edit  
@source = @article.sources.new  
end

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 21, 2009, 5:06pm UTC](https://www.ruby-forum.com/t/methodnotallowed/175797/3 "2009-09-21T17:06:03Z")

</div>

I added

\<% form\_for([@article, @source), :method =\> :put, :url =\> {:action =\>  
“update”}) do |f| %\>

and things seem to be working now.

Thanks for taking the time to read my post, and offering suggestions!

-Kevin

On Sep 21, 3:02 am, Amar D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
