Is it possible to provide different submit button values depending on the current controller/view?
So having 2 views:
=# app/views/devise/sessions.new.html.haml
%h2 Sign in
= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
= f.input :email
= f.input :password
= f.input :remember_me, as: :boolean
= f.button :submit
and
=# app/views/registrations/new.html.haml
= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
= devise_error_messages!
= f.input :first_name
= f.input :last_name
= f.input :email
= f.input :password
= f.input :password_confirmation
= f.button :submit
I want to show Sign in on the first and Sign up on the 2nd view without changing the view itself.
FYI, Localising submit buttons is possible via:
# config/locales/en.yml
en:
helpers:
submit:
user:
create: 'Sign up'
But unfortunately I can’t see how to distinguish between the views above (or controllers) to give different messages for submit buttons.
So the question is how the en.yml file should look like to achieve that?
I18n provides standard way to distinguish between controllers:
Your forms require a little change (the same for sessions and registrations):
Unfortunately I didn’t find a more easy way to do it without that little
t('.create')with simple_form.Look at that
.(dot) before create. Rails will scopecreateby controller name. In our case users/sessions_controller became ‘users.sessions’, the same for registrations.