问题描述:

im creating my first FORM in rails and i want be able to edit my categories which are in db.

_form.html.erb

<%= form_for(@category) do |f| %>

<% if @category.errors.any? %>

<div id="error_explanation">

<h2><%= pluralize(@category.errors.count, "error") %> brání v uložení kategorie.</h2>

<ul>

<% @category.errors.full_messages.each do |msg| %>

<li><%= msg %></li>

<% end %>

</ul>

</div>

<% end %>

<div class="field">

<%= f.label :name %><br />

<%= f.text_field :name %>

</div>

<div class="actions">

<%= f.submit %>

</div>

<% end %>

edit.html.erb

<%= render 'form' %>

<%= link_to 'Show', @category %> |

<%= link_to 'Back', backend_categories_path %>

URL:

http://localhost:3000/backend/categories/1/edit

Error:

undefined method `category_path' for #<#<Class:0x46696f8>:0x3f38478>

Routes:

 home_index GET /home/index(.:format) home#index

root / home#index

contact /contact(.:format) home#contact

backend_root /backend(.:format) backend/admin#index

backend_categories GET /backend/categories(.:format) backend/categories#index

POST /backend/categories(.:format) backend/categories#create

new_backend_category GET /backend/categories/new(.:format) backend/categories#new

edit_backend_category GET /backend/categories/:id/edit(.:format) backend/categories#edit

backend_category GET /backend/categories/:id(.:format) backend/categories#show

PUT /backend/categories/:id(.:format) backend/categories#update

DELETE /backend/categories/:id(.:format) backend/categories#destroy

I also have new form which is rendering ok

new.html.erb

<%= form_for @category, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %>

<%= f.text_field :name %>

<%= f.submit "Vytvořit" %>

<% end %>

So i have a question why edit form isnt working and what is benefit of having form in separate file ? Thank you

网友答案:

You need to supply the /backend/ portion of the route; try this:

<%= form_for [:backend, @category] do |f| %>
相关阅读:
Top