logesh
logesh

Reputation: 2672

How to change devise such that i can add few other fields and show it as profile information

I am following https://github.com/plataformatec/devise_example.git which really is so good but i need to do some additions to it and do not know how to do.

I want to create an api for iphone app and the initial process is create new user by signup and then the account has to be confirmed in mail, and once confirmed the user can login and view his details like name, email, password, language, country, etc... But in this example, after logging in we can view the account info but the password field is left empty and then there are only two fields email and password. Also i want to know whether this devise example can be used as api and please tell me how to add the rest of the fields like language, country and similar things to the user account information. And if this is not possible, then how can i do all these things.Please help me. Also tell me if there is any example.

Upvotes: 1

Views: 162

Answers (1)

niiru
niiru

Reputation: 5112

The user model you create with devise is in many ways just like other models, so you can modify it with a migration. In your console, at the rails application root:

rails g migration AddCountryAndLanguageAndNameAndEmailToUsers country:string language:string name:string email:string
rake db:migrate

You of course have to modify your views (and probably the attr_accessible line in your model) to add these fields.

Devise doesn't store the users' passwords; instead, it stores a hash of the password. Storing a user's password directly is generally considered a bad practice. However, if you're dead set on it, there's no reason you can't modify the above migration to include a plain text password column.

Using as JSON:

Rabl is a great gem for JSON templates.

Otherwise, in your Users Controller:

class UsersController
  def show
    @user = User.find params[:id]
    respond_to do |format|
      format.html
      format.json { render json: @user }
    end
  end

  def index
    @users = User.all
    respond_to do |format|
      format.html
      format.json { render json: @users }
    end
  end
end

And so forth...

Upvotes: 3

Related Questions