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??
我认为您想要:url => category_url(@category)
(非复数)。
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%>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.