Reputation: 483
I'm trying to update my user from a different view than the default registration/edit view. I haven't set the form up all the way yet, but i'm having routing issues to begin with.
This is my form:
%section#profile-editor
.row
.small-12.columns
%h2 Edit Profile
.row
.small-12.columns
.well
=form_tag(edit_thing_registration_path,method: 'PUT', id: "my-awesome-dropzone.dropzone") do
.row
.small-4.columns
%input#photo-dropzone{:name => "file", :type => "file"}/
.small-8.columns
.row
.small-12.columns
%label{:for => "Name"} Name
%input{:name => "Name", :type => "text"}/
.small-6.columns
%label{:for => "Website"} Website
%input{:name => "Website", :type => "text"}/
.small-6.columns
%label{:for => "Itunes"} Itunes URL
%input{:name => "Itunes", :type => "text"}/
.small-6.columns
%label{:for => "Video"} Youtube Video URL (For Profile)
%input{:name => "Video", :type => "text"}/
.small-6.columns
%label{:for => "Email"} Admin Email
%input{:name => "Email", :type => "text"}/
.row
.small-12.columns.pad-top
%label{:for => "RTE"} Content
%input.jqte{:name => "input", :type => "text", :value => ""}/
= submit_tag "Submit", class: "button button-green"
This is my route:
devise_for :things, controllers: { registrations: "things/devise/registrations", sessions: "things/devise/sessions"}
Controller:
class things::Devise::RegistrationsController < Devise::RegistrationsController
def update
# For Rails 4
account_update_params = devise_parameter_sanitizer.sanitize(:account_update)
# For Rails 3
# account_update_params = params[:user]
# required for settings form to submit when password is left blank
if account_update_params[:password].blank?
account_update_params.delete("password")
account_update_params.delete("password_confirmation")
end
@user = thing.find(current_thing.id)
if @user.update_attributes(account_update_params)
set_flash_message :notice, :updated
# Sign in the user bypassing validation in case their password changed
sign_in @user, :bypass => true
redirect_to thing_path(@user)
else
render "edit"
end
end
What happens when I click submit:
No route matches [PUT] "/things/edit"
Rake routes:
new_thing_session GET /things/sign_in(.:format) things/devise/sessions#new
thing_session POST /things/sign_in(.:format) things/devise/sessions#create
destroy_thing_session DELETE /things/sign_out(.:format) things/devise/sessions#destroy
thing_password POST /things/password(.:format) devise/passwords#create
new_thing_password GET /things/password/new(.:format) devise/passwords#new
edit_thing_password GET /things/password/edit(.:format) devise/passwords#edit
PATCH /things/password(.:format) devise/passwords#update
PUT /things/password(.:format) devise/passwords#update
cancel_thing_registration GET /things/cancel(.:format) things/devise/registrations#cancel
thing_registration POST /things(.:format) things/devise/registrations#create
new_thing_registration GET /things/sign_up(.:format) things/devise/registrations#new
edit_thing_registration GET /things/edit(.:format) things/devise/registrations#edit
PATCH /things(.:format) things/devise/registrations#update
PUT /things(.:format) things/devise/registrations#update
DELETE /things(.:format) things/devise/registrations#destroy
Upvotes: 0
Views: 311
Reputation: 4593
If you want to be able to render devise forms from any controller you should put this in your application helper:
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
Hope this helps.
Upvotes: 1
Reputation: 11494
You're using a url that maps to a GET request in your form: edit_artist_registration_path
. Instead, you'll want the url of the form to point to the PUT
or PATCH
url for artist registration:
form_tag(artist_registration_path, method: 'PUT', id: "my-awesome-dropzone.dropzone")
Upvotes: 0