Ruby on rails Rails 3-通过表单_在有效URL中生成嵌套资源?
我有以下表格_用于标记,配置文件包含它生成的URL,它无效,即标记如下:Ruby on rails Rails 3-通过表单_在有效URL中生成嵌套资源?,ruby-on-rails,Ruby On Rails,我有以下表格_用于标记,配置文件包含它生成的URL,它无效,即标记如下: <%= form_for([current_user,@profile], :html =>{:class => "contact_form",:multipart => true}) do |f| %> 用户模型 class User < ActiveRecord::Base has_one :profile, :inverse_of => :user accepts_
<%= form_for([current_user,@profile], :html =>{:class => "contact_form",:multipart => true}) do |f| %>
用户模型
class User < ActiveRecord::Base
has_one :profile, :inverse_of => :user
accepts_nested_attributes_for :profile
我也有同样的问题。我的解决方案是,您必须像这样直接声明url:
<%= form_for([current_user,@profile], :url => user_profile_path, :html =>{:class => "contact_form",:multipart => true}) do |f| %>
user_profile_path,:html=>{:class=>“contact_form”,“multipart=>true})do | f |%>
虽然我真的不知道为什么会发生这种事-也许任何人都可以解释
class Profile < ActiveRecord::Base
belongs_to :user
validates_presence_of :user
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
user_profile POST /users/:user_id/profile(.:format) profiles#create
new_user_profile GET /users/:user_id/profile/new(.:format) profiles#new
edit_user_profile GET /users/:user_id/profile/edit(.:format) profiles#edit
GET /users/:user_id/profile(.:format) profiles#show
PUT /users/:user_id/profile(.:format) profiles#update
DELETE /users/:user_id/profile(.:format) profiles#destroy
<%= form_for([current_user,@profile], :url => user_profile_path, :html =>{:class => "contact_form",:multipart => true}) do |f| %>