views:

59

answers:

2

Not sure what's going on. I've used the following bit of code to try and edit the name of a category, but I'm getting the error message above. My code for the form and submit for the edit is: -

<% form_for :category, :url => categories_url(@category),:html => { :method => :put } do |f| -%>
<p>Name: <br /><%= f.text_field :name, :size => 60 %></p>
<%= submit_tag 'Save' %> or <%= link_to 'cancel', admin_categories_url%>

So pretty straight forward stuff. My controller code is: - def edit @category = Category.find(params[:id]) end

# PUT /categories/1 # PUT /categories/1.xml def update @category = Category.find(params[:id]) @category.update_attributes(params[:category])

respond_to do |wants|
  wants.html { redirect_to admin_categories_url }
  wants.xml  { render :xml => @category.to_xm }
end  

end

This code has worked for other things - such as blog articles, so I'm not sure where I{"m going wrong. Help??

+1  A: 

I think you want :url => category_url(@category) (non-plural).

rspeicher
Thanks, such a simple think and it worked! Blah!
mrbernz
+1  A: 

This tends to be a bit cleaner... Let the Routing system figure out how best to save the @category.

/app/controllers/admin_categories_controller.rb (guessed at this)

def new
  @category = Category.new
end

/app/views/admin_categories/new.html.erb

<% form_for @category do |f| %>
<p>
<%= f.label :name%>: <%= f.text_field :name, :size=>60%>
</p>
<%= f.submit :save%> or <%= link_to 'cancel', admin_categories_url%>
Jesse Wolgamott
Thanks I'll try this also.
mrbernz