Change A Devise Error Message - ruby-on-rails

I'm using Rails 4 and Devise 3.4.1
I would like to change the messages sentences that appear in case of an error or a notification in the devise_error_messages. How can I do that?
Thank you

Corresponding I18n translation-files are located in config/locales folder (devise.en.yml for ex). You can make changes there.

Related

Rails internationalization - is there better way to keep messages in english?

I recently make a decision to translate my tiny rails app with I18n gem as it described here.
While a testing, as it expected, I got a error messages from activerecord and devise:
translation missing: ru.devise.failure.user.not_found_in_database
translation missing: ru.activerecord.errors.models.user.attributes.name.taken
At this moment I know only one way to set up massages with custom locale - simply copy en.yml file which contains messages into my custom ru.yml, but it's weird way.
Maybe I missed something?
Cheers!
You can use the default option (related question)
I also advise you to look into the rails-18n gem for common translations
Devise provide common translations on their wiki
You can also set up a fallback locale to avoid missing translations (related question)

Translate Rails Devise error messages

I'm using devise gem to implement authentication in my Ruby On Rails application. Sometimes error messages are displayed such as:
Prohibited an error being wellness saved from this user: Password is
too short (minimum is 6 characters)
What is the best way to translate these messages to another language?
Go to config/locales and copy devise.en.yml, giving the file a name like devise.other_language_initials.yml. Then add your own translations.
For more info on how to translate your application, go here.
The fastest way is downloading a translation file to the language you want. You can find more about in this link.
What you are going to find there is a bunch of files in different languages for Devise flash notifications that you can download and add to you application under config/locales.
Hope that helps you! :)

Rails, Formtastic - model name not showing on form buttons

I have just deployed an existing app to a new server and have noticed that where model names are automatically generated (by Formtastic) it instead outputs {{model}} rather than the expected name.
For example, in the linked image it should read 'Create Category' but instead reads 'Create {{model}}'
https://skitch.com/simon180/rr4w9/example
I don't know where to start in figuring what causes this.
Rails version is 2.3.5 (vendored) and gems vendored too.
Any suggestions gratefully received!
Thanks
Simon
Have a look in the formtastic gem, depending on what version you have, the file will be
/lib/formtastic/i18n.rb
or
formtastic/lib/locale/en.yml
it should have something like this:
'Create %{model}'
but yours will have:
'Create {{model}}'
Thats the old format. Change occurrences of {{foo}} to %{foo}
or
Updating the formtastic gem should do the trick
Another option is to downgrade the i18n gem to 0.4.1 this problem will disappear.
The problem is with the i18n gem version. From version 0.4.1 on, the way of accessing variables isn't {{variable}} anymore.

Attachment_fu issue

I am trying to use attachment_fu + image science on jRuby-1.5.2 and Rails 3. I have followed the attachment_fu docs. However, when I upload the form form the browser, i get an error on validate_as_attachment saying size cannot be blank. This is what the log says
size can't be blank translation missing: en.activerecord.errors.messages.inclusion
when I modify the plugin to forget size check or not add validate_as_attachment check, an entry is made in the DB table but the actual file is not transfered.
Can anyone please guide me, Also is there a Rails3 compatible plugin available.
Thanks for the help
AttachmentFu is rather old. I don't know if it's still being maintained actively.
The alternatives that pop into mind are Paperclip and Carrierwave. Paperclip is the older one, good, but feels a bit dated. Carrierwave feels more in sync with Rails 3 and I've been hearing a lot of great things about it.
You need to add to your config/locales/en.yml file something like
en:
activerecord:
errors:
messages:
inclusion: "Attachment"
I suggest you change your attachment_fu to be a gem,
if you haven't done it yet, add this on your Gemfile:
git "https://github.com/pothoven/attachment_fu.git" do
gem 'pothoven-attachment_fu'
end
Because this version I'm providing the link here has the patch for making it work on rails 3 and 4.
This error you are getting happens normally when you have compatibility issues.
After updating your attachment_fu then make sure that, whenever you instantiate a new image you do something like this:
image = YourImageModel.new()
image.uploaded_data = image_data_here
If you check on the implementation, the signature has changed, that's why you should change the initializations of your image models to be like this

how to change devise's flash[:notice] in rails

I'm using rails 2.3.5 and devise 1.0.6.
I'm having users confirm account's with email.
However, when a new user sign's up the flash notice says "The user was successfully created" which it was but it doesn't tell the user that they need to confirm their their email unless they try to log in and devise's flash notice still doesn't explain that they have to confirm through email.
Where is this flash notice located in the gem and how can I change it? Or what is a better way to fix this problem.
Just enable i18n in your project and edit the default locale (en.devise.yml) or download new ones from
https://github.com/plataformatec/devise/wiki/i18n
Flash messages for the devise gem can be altered in the locales directory (YourRailsApp/config/locales/devise.en.yml).
Just change the devise.en.yml to your liking, it doesn't really take any programming knowledge.
If you are new to rails the locales directory is for I18n translations which is rails way of translating words albeit statically but it works well for simple projects.

Resources