Translate devise labels in registration? - ruby-on-rails

I want to translate my labels in registration form, but I can't see what is the schema to follow in my .es locale. It wont work with "registrations". Someone knows? I can't find a correct answer in all the internet. Thanks
.es locale
devise:
registrations:
name: "Nombre"
email: "Email"
password: "Contraseña"
password_confirmation: "Recordarme"

It's done via active record translations
es:
activerecord:
attributes:
user:
password: "Contraseña"
email: "Email"
password_confirmation: "Recordarme"

Related

how to locale field Devise?

I used gem Devise for authentication in my application . I want to change label text for below input
<%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %>
but I can not find this field for standard renaming either in the service files or in the devise locale
how to locale this field ?
presently
check-box "Remember me"
_
need
check-box "Запомнить меня"
en.yml
en:
activerecord:
attributes:
user:
email: Email
password: Password
remember_me: Remember me
create new file for any other locale and add translated text for that language
de.yml
de:
activerecord:
attributes:
user:
email: "email in de"
password: "Password in de"
remember_me: "Remember me in de"
You can read more about devise translation here
Here is the very useful site for translations - https://www.localeapp.com/projects/377/translations/5250293?in_locale=5291

Rails 4.1 Devise 3.3 column users.password does not exist

I want to create a user manually through the console as such:
User.find_or_create_by(email: "user#mail.com", first_name: "Stan", last_name: "Smith", password: "password", password_confirmation: "password", confirmed_at: Time.now)
I have done this many times in past projects but this time it's not working. It is not picking up the Devise password model attribute so this is the error I get:
PG::UndefinedColumn: ERROR: column users.password does not exist
I have Rails 4.1.4 and Devise 3.3.0. Did something change in the latest versions?
Thanks.
Instead of User.find_or_create_by you should be using User.create.
Devise accepts a password and password confirmation on creation but the actual table only has a column called encrypted_password.
The "find" portion of User.find_or_create_by is looking for a column called "password" which doesn't exist.
Still if you want to use find_or_create_by, it accepts block:
User.find_or_create_by(email: "user#mail.com", first_name: "Stan", last_name: "Smith") do |user|
user.password = "password"
user.confirmed_at = Time.now
end

Omniauth-facebook hash not showing Facebook 'username' field, using rails 3

I've set up my rails 3 app to use omniauth-facebook, everything works fine but when I look at the omniauth hash as yaml there is no 'nickname' field, I can get the 'name' and 'email' but my validations fail to create a user because I can't grab the nickname for my app's username requirement.
I've double checked my facebook account, under "Settings", and my username is displayed. ANy ideas why this would be happening? Thanks for the help.
Here is an example of my omniauth hash, i've placed 'X' for privacy reason:
--- !ruby/hash:OmniAuth::AuthHash
provider: facebook
uid: 'XXXXXXXXXXXXX'
info: !ruby/hash:OmniAuth::AuthHash::InfoHash
email: XXXX#XXXX.XX
name: XXXX XXXX
first_name: XXXX
last_name: XXXX
image: http://graph.facebook.com/XXXXXXXXXXXXX/picture
urls: !ruby/hash:OmniAuth::AuthHash
Facebook: https://www.facebook.com/app_scoped_user_id/XXXXXXXXXXXXX/
verified: true
credentials: !ruby/hash:OmniAuth::AuthHash
token: ACCESS_TOKEN
expires_at: 1406357169
expires: true
extra: !ruby/hash:OmniAuth::AuthHash
raw_info: !ruby/hash:OmniAuth::AuthHash
id: 'XXXXXXXXXXXXXXX'
email: XXXX#XXXX.XX
first_name: XXXX
gender: male
last_name: XXXX
link: https://www.facebook.com/app_scoped_user_id/XXXXXXXXXXXXX/
locale: en_US
name: XXXX XXXX
timezone: 7
updated_time: '2014-05-07T00:58:12+0000'
verified: true
There's no field nickname, do you mean username? If so it's no longer available if you use the Graph API v2.0.
References:
https://developers.facebook.com/docs/apps/changelog#v2_0_graph_api
https://developers.facebook.com/docs/graph-api/reference/v2.0/user/#fields
I know this is an old question.
Since facebook now does not support fetching username at time of login, a workaround for getting user name would be, to call GraphRequest.newMeRequest() from the onSuccess() method of facebook login button

Troubleshooting 'Unknown record property / related component "user" on "sfGuardUserProfile"' when loading fixture data

I am some trouble loading fixture data, that I have added manually in my admin backend and then simply exported the data using 'symfony doctrine:data-dump'
schema.yml
http://pastebin.com/5LTzNtU1
fixtures.yml (snippet)
http://pastebin.com/CNWyhrgc
Now everything works fine when I run symfony doctrine:build --all, but when i try to load the data, I get:
Unknown record property / related component "user" on "sfGuardUserProfile"
This is really odd, as I have saved users and they've gone into both tables fine, just not when loading the fixtures that I exported fomr the database.
Does anyone have any ideas what the problem could be?
Thanks
Try this. create users.yml with
sfGuardUser:
sfGuardUser_1:
email_address: test#example.com
username: test_user
algorithm: sha1
salt: 6fdcd99a2c73d6270f1ed8dbbf7ccd3e
password: fed98ad16c318197d16a2d7375f81e1afbce0792
is_active: true
is_super_admin: true
last_login: '2011-05-03 09:37:08'
first_name: ''
last_name: ''
created_at: '2011-04-11 11:29:02'
updated_at: '2011-05-03 09:37:08'
and profile.yml with
sfGuardUserProfile:
sfGuardUserProfile_1:
User: sfGuardUser_1
email_new: test#example.com
firstname: Test
lastname: User
validate_at: null
validate: null
created_at: '2011-04-19 15:46:16'
updated_at: '2011-04-19 15:49:14'
Maybe it help you.

Create a devise user from Ruby console

Any idea on how to create and save a new User object with devise from the ruby console?
When I tried to save it, I'm getting always false. I guess I'm missing something but I'm unable to find any related info.
You can add false to the save method to skip the validations if you want.
User.new({:email => "guy#gmail.com", :roles => ["admin"], :password => "111111", :password_confirmation => "111111" }).save(false)
Otherwise I'd do this
User.create!({:email => "guy#gmail.com", :roles => ["admin"], :password => "111111", :password_confirmation => "111111" })
If you have confirmable module enabled for devise, make sure you are setting the confirmed_at value to something like Time.now while creating.
You should be able to do this using
u = User.new(:email => "user#name.com", :password => 'password', :password_confirmation => 'password')
u.save
if this returns false, you can call
u.errors
to see what's gone wrong.
When on your model has :confirmable option this mean the object user should be confirm first. You can do two ways to save user.
a. first is skip confirmation:
newuser = User.new({email: 'superadmin1#testing.com', password: 'password', password_confirmation: 'password'})
newuser.skip_confirmation!
newuser.save
b. or use confirm! :
newuser = User.new({email: 'superadmin2#testing.com', password: 'password', password_confirmation: 'password'})
newuser.confirm!
newuser.save
If you want to avoid sending confirmation emails, the best choice is:
u = User.new({
email: 'demo#greenant.com.br',
password: '12feijaocomarroz',
password_confirmation: '12feijaocomarroz'
})
u.confirm
u.save
So if you're using a fake email or have no internet connection, that'll avoid errors.
None of the above answers worked for me.
This is what I did:
User.create(email: "a#a.com", password: "asdasd", password_confirmation: "asdasd")
Keep in mind that the password must be bigger than 6 characters.

Resources