I am using rail 4.2 and ruby 2.2.0p0, I need to submit form which
belongs to user table, once the user authenticate and for authentication
I am using devise, Do I need to create user controller and view manually
or
I have created two directory named as my_devise one under controllers
and other under views. I followed
this(http://stackoverflow.com/questions/3546289/override-devise-registrations-controller)
for the approach which I took. I
am getting “uninitalized constant MyDeviseController” error.Here is the
list of files which I modified.
my_devise/registrations_controller.rb
class MyDevise::RegistrationsController <
Devise::RegistrationsController
def update
@user = current_user
if @user.update_attributes(user_params)
# Handle a successful update.
else
redirect_to ‘my_devise/registrations’
end
end
private
def user_params
params.require(:user).permit(:title, :font, :description,
:bgcolor)
end
end
my_devise/registration.html.erb
<%= form_for :user, @user, :url => url_for(:controller =>
‘registrations’, :action => ‘update’) do |u|%>
<%= u.label :title %>
<%= u.text_field :title %>
<%= u.label :description %>
<%= u.text_field :description %>
<%= u.label :back_ground_color %>
Orange
Green
Blue
Pink
Yellow
White
<%= u.label :font %>
Times new Roman
Verdana
Arial
serif
<%= u.submit %>
<% end %>
routes.rb
devise_for :users, :controllers => {:registrations =>
“my_devise/registrations”}
devise_scope :user do
authenticated :user do
root :to => ‘my_devise#registration’, as: :authenticated_root
end
unauthenticated :user do
root :to => ‘devise/registrations#new’, as: :unauthenticated_root
end
end
schema.rb
ActiveRecord::Schema.define(version: 20150420060137) do
create_table “users”, force: :cascade do |t|
t.string “email”, default: “”, null: false
t.string “encrypted_password”, default: “”, null: false
t.string “reset_password_token”
t.datetime “reset_password_sent_at”
t.datetime “remember_created_at”
t.integer “sign_in_count”, default: 0, null: false
t.datetime “current_sign_in_at”
t.datetime “last_sign_in_at”
t.string “current_sign_in_ip”
t.string “last_sign_in_ip”
t.datetime “created_at”
t.datetime “updated_at”
t.text “title”
t.text “font”
t.string “bgcolor”
t.text “description”
end