Michael Lombardo Michael Lombardo - 1 year ago 84
Ruby Question

undefined method `user_verification_path' (has_one relationship)

I have a has_one relation with

. I want to make a form that references both!! How can I do this? I run into this error!!! Thanks!


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'

Here is my form 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 %>

Here is my controller!!!

def paypal_verification
# @verification = @user.verification.new
@user = current_user
@verification = Verification.create(params[:verification])
@user.verification = @verification


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

resources :revisers
resources :photos
resources :pages

#make sure to change this to user!!! instead of reservations!!!
resources :reviser do
resources :reservations, only: [:create]

resources :user do
resources :verifications, only: [:create]

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'

Answer Source

Since you are doing a nested route to do the verification rails will expect this route:

 Prefix Verb   URI Pattern                            Controller#Action
 user_verifications POST   /user/:user_id/verifications(.:format) verifications#create

You can check with bin/rails routes

So in your form you need to use user_verifications_path but since you have instance variables here is what you need to do

<%= form_for([@user, @user.verification]) do |f| %>

That line should say this

<%= form_for(Verification.new, url: user_verifications_path(@user)) do |f| %>

Uer verification will go to /users/ID/verifications with a Verifications.new as new model that you pass in to your controller. This should be inside verifications#create. You have not included this controller in your question. So if this does not work please update your question with this method as well.


if you want to update already created verification then for PATH/ or put the only thing that is change is instance of record and path, so it goes to /users/ID/verifications/VERIFICATIONID

Your form needs to say something like this

form_for(@user.verification, url: user_verifications_path(@user, @user.verification)

Hope it helps