-2

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
Community
  • 1
  • 1
cyborg
  • 870
  • 1
  • 15
  • 34
  • Can you explain proper. Not getting your point what do you want to do exactly. – SSR Apr 20 '15 at 06:00
  • @VDN I have gone through all possible way but I couldn't able to achieve, so I think I am doing some mistake in approach – cyborg Apr 20 '15 at 06:04
  • http://stackoverflow.com/questions/29725744/how-to-save-static-page-attributes-in-user-model – cyborg Apr 20 '15 at 06:05
  • @SSR Pls go through all links, I have not got a single correct solution http://stackoverflow.com/questions/29689664/how-can-user-modify-color-page-and-title-in-rails-application – cyborg Apr 20 '15 at 06:06

1 Answers1

0

What you need to do is that you want to redirect to a different page after the signup. There are great tutorials provided by devise:

How To Redirect to a specific page on successful sign up

For more tutorials visit:

https://github.com/plataformatec/devise/wiki/How-Tos

If you face any error or issue which you cannot search while implementing it then post it here.

Deepesh
  • 6,138
  • 1
  • 24
  • 41