Rails 3 Routes issue on form Edit -
basically whats happening can create new item gets saved table in db. when go edit item, form opens up, make change , when go submit, takes me same url edit page , gives me routing error no route matches "/support/14/edit" although if enter in address bar opens edit form fine, doesn't have of changes saved. here code.
routes.rb
resources :support
support_controller.rb
def new @support_item = support.new respond_to |format| format.html # new.html.erb format.xml { render :xml => @support_item } end end # /support/1/edit def edit @support_item = support.find(params[:id]) end # post /support # post /support.xml def create @support_item = support.new(params[:support_item]) respond_to |format| if @support_item.save format.html { redirect_to("/support", :notice => 'question created.') } else format.html { render :action => "new" } end end end # put /support/1 # put /support/1.xml def update @support_item = support.find(params[:id]) respond_to |format| if @support_item.update_attributes(params[:support_item]) format.html { redirect_to("/", :notice => 'question updated.') } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @support_item.errors, :status => :unprocessable_entity } end end end
support.rb
class support < activerecord::base belongs_to :role scope :admin_available, order("role_id asc") support.all end def self.available(user) questions = where(:role_id => 1) questions += where(:role_id => user.roles) questions end end
_form.html.erb
<% if @support_item.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@support_item.errors.count, "error") %> prohibited question being saved:</h2> <ul> <% @support_item.errors.full_messages.each |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= f.label "support item for:" %><br /> <%= f.collection_select :role_id, role.find_by_max(5), :id, :name, {:default => 'everyone'} %> </div> <div class="field"> <%= f.label :question %><br /> <%= f.text_field :question, :class => 'genform_question'%> </div> <div class="field"> <%= f.label :answer %><br /> <%= f.text_area :answer, :class => 'genform_textarea' %> </div> <div class="field"> <%= f.label :url %><br /> <%= f.text_field :url, :class => 'genform_question' %> </div> <div class="actions"> <%= f.submit %> </div>
new.html.erb
<h1>new support item</h1> <% form_for @support_item, :url => { :action => "create" }, :html => { :method => :post } |f| %> <%= render 'form', :f => f %> <% end %>
edit.html.erb
<h1>editing support item</h1> <% form_for @support_item, :url => { :action => "edit" }, :html => { :method => :post } |f| %> <%= render 'form', :f => f %> <% end %>
i believe thats relavent code.
<h1>editing support item</h1> <% form_for @support_item |f| %> <%= render 'form', :f => f %> <% end %>
you overriding url. should able auto-generated if doing standard rest. if doesn't work out, know don't want submit /support_items/1/edit, want submit /support_items/1.
Comments
Post a Comment