收录日期:2019/06/20 13:38:51 时间:2010-06-22 20:26:52 标签:ruby-on-rails

I can make a new , and that seems to work. But edit/update does not.

My controller :

def edit
  @admin_wysi = AdminWysi.find(params[:id])
end

def update
  @admin_wysi = AdminWysi.find(params[:id])

  if @admin_wysi.update_attributes(params[:admin_wysis])
    redirect_to admin_admin_wysis_path
  end
end

And my HAML..

- form_for @admin_wysi, :url => admin_admin_wysis_path do |f|
  = f.cktext_area :post_published, :cols => '70', :rows => '30', :width => '555px', :height => '240px', :toolbar => 'HQ'
  = f.submit 'Update', {:class => 'button'}

This is literally copy and pasted practically from my "new", so I'm guessing the problem HAS to be from my controller. Also there are no errors, and the SQL is identical in its injections as it was with the 'new'.

Thanks a bazillion everyone.

you need to have an edit form that is slightly different

- form_for @admin_wysi, :url => admin_admin_wysis_path(@admin_wysi) do |f|

And that should be edit.html.haml

UPDATE: it appears you have already done this but you need the following line in your routes.rb in order for the named routes to work.

map.name_space :admin do |admin|
  admin.resources :admin_wysi
end

UPDATE: that should be

- form_for @admin_wysi, :url => admin_admin_wysi_path(@admin_wysi) do |f|

to trigger the update action.

Shouldn't it be

@admin_wysi.update_attributes(params[:admin_wysi]

instead of

@admin_wysi.update_attributes(params[:admin_wysis]

?