简体   繁体   中英

Rails 3 Rspec form_for Deprecation Warning

I have a form_for in my application which looks like:

<%= form_for :user, @user, :url => { :controller => 'users', :action => 'update' }, :html => { :multipart => true, :method => 'put' } do |f| %>

This works fine. However, when I run my tests with Rspec I always get:

DEPRECATION WARNING: Using form_for(:name, @resource) is deprecated. Please use form_for(@resource, :as => :name) instead.

Which seems to go against what is written in the Rails 3 forms guide . Is this just a bug in rspec or is it actually a deprecation?

You should just be able to do this

<%= form_for @user, :html => {:multipart => true} %>

Since Rails will know that @user is an existing record, it'll know to do a PUT request to users_controller#update .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM