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
soloriok-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 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 -- Posted via http://www.ruby-forum.com/.
soloriok-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2009-Sep-21 15:04 UTC
Re: MethodNotAllowed
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 Daxini
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> solor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 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
> --
> Posted viahttp://www.ruby-forum.com/.