resource
is a variable set by the Devise gem. In order to move the above code somewhere else, it means that you will have to take care of setting the resource
variable yourself.
Basically a rails form_for
wants to take the instance of the object you want to create / edit.
<%= form_for instance_object ...
In your case you'll need to first fetch the user you want to edit (or use current_user) and then give it to the form_for
helper method:
<%= form_for current_user ...
or by setting the @user
instance variable in your controller first:
def new
@user = User.new
end
def edit
@user = User.find(some_id)
end
Then in your view:
<%= form_for @user ...
Don't forget to replace all the resource
occurences by your instance variable.