I want to fire the devise/registrations/edit.html.erb
in a modal in my app.
Right now, I have everything working, except that when the modal is fired I don't see the current_user
information in the form fields.
When I go to /settings
(which is the route for users/edit
in my app), it shows the current_user
information correctly.
But it doesn't when I see it in the modal within the app.
What I did was created a partial based on the edit, and am now rendering that partial.
So this is the partial: devise/registrations/_edit.html.erb
:
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, :required => true, :autofocus => true %>
<%= f.input :name, :autofocus => true %>
<%= f.input :avatar %>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<p>Currently waiting confirmation for: <%= resource.unconfirmed_email %></p>
<% end %>
<%= f.input :password, :autocomplete => "off", :hint => "leave it blank if you don't want to change it", :required => false %>
<%= f.input :password_confirmation, :required => false %>
<%= f.input :current_password, :hint => "we need your current password to confirm your changes", :required => true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Update" %>
</div>
<% end %>
<%= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %>
<%= link_to "Back", :back %>
This is where it gets rendered:
<div id="overlay"> </div>
<div class="popup center-block" id="edit_profile">
<div class="titles clearfix">
<!-- <h2>Edit Account</h2> -->
<h2>Edit <%= resource_name.to_s.humanize %></h2>
</div>
<div class="content">
<%= render "devise/registrations/edit" %>
</div>
</div>
It gets rendered on my Dashboard#Index
, so this is what my dashboard_helper.rb
looks like:
module DashboardHelper
def resource_name
current_user.name || :user
end
def resource
# @resource ||= User.new
@resource ||= current_user
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
How do I get the edit form displayed in the modal to show the current_user
info?
Edit 1
I even tried this in my view:
<%= render "devise/registrations/edit", locals: { resource: current_user, :resource_name => User } %>
But it still hasn't worked.
Edit 2
When I use pry
to debug this, it shows me that the resource
variable is empty - this is from the devise/registrations/_edit.html.erb
:
[1] pry(#<#<Class:0x007fedf8be85c8>>)> resource_name
=> :user
[2] pry(#<#<Class:0x007fedf8be85c8>>)> resource
=> #<User id: nil, email: "", encrypted_password: "", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: nil, updated_at: nil, name: nil, confirmation_token: nil, confirmed_at: nil, confirmation_sent_at: nil, unconfirmed_email: nil, invitation_relation: nil, avatar: nil, invitation_token: nil, invitation_created_at: nil, invitation_sent_at: nil, invitation_accepted_at: nil, invitation_limit: nil, invited_by_id: nil, invited_by_type: nil, invitations_count: 0, bio: nil>
So it seems that the DashboardHelper override is not working.