I’m trying to show the data from the user through a form so he can be able to edit any field. I’m using simple_form for this, and devise for authentication purposes.
I keep getting the undefined method user_path error.
This is my controller
class HomeController < ApplicationController
before_filter :authenticate_user!
def index
#Mostramos menu de opciones
end
def perfil
@user = User.find(current_user.id)
end
def editar
@user = User.find(current_user.id)
end
end
The view for perfil.html.erb
<h1>showing user data</h1>
<%= simple_form_for @user do |f| %>
<%= f.input :nombre %>
<%= f.input :username %>
<%= f.input :rut %>
<%= f.input :ciudad %>
<%= f.input :direccion %>
<%= f.input :groupId %>
<%= f.button :submit %>
<% end %>
<%= link_to "Editar datos", :action => :editar %>
<br>
<%= link_to "Volver", :action => :index %>
And my routes file
devise_for :users
match "perfil" => "home#perfil"
match "editar" => "home#editar"
The error is around this line in the view <%= simple_form_for @user do |f| %>
I’ve been searching for guides or insights on what I’m doing wrong (I’m almost sure is something bad done or missing in routes.rb). Any insight would be much appreciated.
This would post to the form to
users_controllercontroller and action depending on the context.devise_for :usersdoes not generate that controller for you, instead you haveregistrations_controlleravailable and in fact, you don’t need to create the edit form, there’s already one available at urlusers/editfor the current user.To customize the default templates, run
rails generate devise:viewsand take a look atapp/views/devise.