facing issue in routes

14 views
Skip to first unread message

Manish K.

unread,
Apr 21, 2015, 12:25:54 PM4/21/15
to rubyonra...@googlegroups.com
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 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|%>
<br >
<p>
<%= u.label :title %><br>
<%= u.text_field :title %>
</p>

<p>
<%= u.label :description %><br>
<%= u.text_field :description %>
</p>

<p> <%= u.label :back_ground_color %><br>
<select name="bgcolor" id="bgcolor">
<option value="#FF3300">Orange</option>
<option value="#00FF00">Green</option>
<option value="#0000FF">Blue</option>
<option value="#FF0066">Pink</option>
<option value="#FFFF00">Yellow</option>
<option value="#FFFFFF">White</option>
</select>
</p>

<p>
<%= u.label :font %><br>
<select name="font" id="font">
<option value="Times New Roman">Times new Roman</option>
<option value="Verdana">Verdana</option>
<option value="Arial">Arial</option>
<option value="sans-serif">serif</option>
</select>
</p>

<br >
<p>
<%= u.submit %>
</p>
<hr >
<div style="background: #{current_user.bg_color};"></div>
<div style="background-color:#{current_user.font.nil? ? '#FFFFFF' :
current_user.font}">
This is the changes made in background
</div>

<div style="background-color:#{current_user.bgcolor.nil? ? '#FFFFFF' :
current_user.bgcolor}">

</div>

<% 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

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Apr 21, 2015, 12:38:39 PM4/21/15
to rubyonra...@googlegroups.com
On 21 April 2015 at 17:25, Manish K. <li...@ruby-forum.com> wrote:
> 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 for the approach which I took. I
> am getting "uninitalized constant MyDeviseController" error.Here is the
> list of files which I modified.

Post the complete error message and tell us which line of code it refers to.

Colin
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a3a889866dcaf55a63f11af1c9bc8a30%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages