我与verification
和user
有一个has_one关系。我想制作一个引用两者的表格!我怎样才能做到这一点?我遇到这个错误!谢谢!
错误日志:
ActionView::Template::Error (undefined method `user_verification_path' for #<#<Class:0x007fcb8bb4e8e0>:0x007fcb89e71998>):
1: <%= form_for([@user, @user.verification]) do |f| %>
2: <%= f.email_field :paypal_email, :class => 'form-control', :placeholder => "Paypal Email", id: 'Pemail' %>
3: <%= f.text_field :paypal_firstname, :class => 'form-control', :placeholder => "Paypal FirstName", id: 'PfirstName' %>
4: <%= f.text_field :paypal_lastname, :class => 'form-control', :placeholder => "Paypal LastName", id: 'PlastName' %>
app/views/users/paypal_verification.html.erb:1:in `_app_views_users_paypal_verification_html_erb__139977708174630313_70256084327900'
&#13;
这是我的表单paypal html
<%= form_for([@user, @user.verification]) do |f| %>
<%= f.email_field :paypal_email, :class => 'form-control', :placeholder => "Paypal Email", id: 'Pemail' %>
<%= f.text_field :paypal_firstname, :class => 'form-control', :placeholder => "Paypal FirstName", id: 'PfirstName' %>
<%= f.text_field :paypal_lastname, :class => 'form-control', :placeholder => "Paypal LastName", id: 'PlastName' %>
<%= f.submit "verify", class: "btn btn-primary" %>
<% end %>
&#13;
这是我的控制器!!!
def paypal_verification
# @verification = @user.verification.new
@user = current_user
@verification = Verification.create(params[:verification])
@user.verification = @verification
end
的routes.rb
devise_for :users ,
:path => '' ,
:path_names => {:sign_in => 'login', :sign_out => 'logout', :edit => 'profile'},
:controllers => {:omniauth_callbacks => 'omniauth_callbacks',
:registrations => 'registrations', :verifications => 'verifications'
}
resources :users, only: [:index, :show] do
end
resources :revisers
resources :photos
resources :pages
#make sure to change this to user!!! instead of reservations!!!
resources :reviser do
resources :reservations, only: [:create]
end
resources :user do
resources :verifications, only: [:create]
end
get '/preload' => 'reservations#preload'
get '/preview' => 'reservations#preview'
get '/your_essays' => 'reservations#your_essays'
get '/your_reservations' => 'reservations#your_reservations'
post '/notify' => 'reservations#notify'
post '/your_essays' => 'reservations#your_essays'
get '/users/:id/paypal_verification' => 'users#paypal_verification'
答案 0 :(得分:1)
由于您正在执行嵌套路由以执行验证,因此将使用此路由:
Prefix Verb URI Pattern Controller#Action
user_verifications POST /user/:user_id/verifications(.:format) verifications#create
您可以查看bin / rails路线
因此,在您的表单中,您需要使用user_verifications_path,但由于您在此处有实例变量,因此您需要执行此操作
<%= form_for([@user, @user.verification]) do |f| %>
该行应该说明这个
<%= form_for(Verification.new, url: user_verifications_path(@user)) do |f| %>
Uer验证将转至/ users / ID / verifications并使用Verifications.new作为传递给控制器的新模型。这应该在内部验证#create。您没有在您的问题中包含此控制器。因此,如果这不起作用,请使用此方法更新您的问题。
修改
如果你想更新已经创建的验证,那么对于PATH /或者唯一的改变就是记录和路径的实例,所以它转到/ users / ID / verifications / VERIFICATIONID
您的表单需要说出类似的内容
form_for(@user.verification, url: user_verifications_path(@user, @user.verification)
希望有所帮助