Create a new Devise user form created with railapps partly to use it

I created a new app with Rails App composer using Devise and Pundit. The composer has created a form to create new users (devise / registrations / new.html.erb), which I would like to do partially, so I can post it on other pages. The form

  <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :role => 'form'}) do |f| %>
    <h3>Sign up</h3>
    <%= devise_error_messages! %>
    <div class="form-group">
      <%= f.label :email %>
      <%= f.email_field :email, :autofocus => true, required: true, class: 'form-control' %>
    </div>
    <div class="form-group">
      <%= f.label :password %>
      <%= f.password_field :password, class: 'form-control' %>
    </div>
    <div class="form-group">
      <%= f.label :password_confirmation %>
      <%= f.password_field :password_confirmation, class: 'form-control' %>
    </div>ate_field :date_of_birth, class: 'form-control' %>
    </div>
     <%= f.submit 'Sign up', :class => 'button right' %>
  <% end %>

      

if i put this in a partial and try to display it on another page i get

undefined local variable or method `resource

      

and this is obvious because in my controller I didn't define anything. The problem is I can't find the controller or what resource

should be in another controller so that I can reuse this.

+3


source to share


1 answer


The resource method you are looking for is here

Resource

appears to be defined by an instance variable with the name of the actual resource you are working with.



So, if you are using a utility for a resource users

, you must define the resource as User.new

on the controller that you want to render this partial, and mark it as helper_method

so that it can be used in views, or just define it directly in the helper.

Alternatively, you can just inherit DeviseController

, which already includes the resource definition and other useful methods.

+1


source







All Articles