I want to write a helper for a submit button, that takes in account the action (create or update) to get the right translation. Here they are :
fr:
submit:
create:
user: "Créer mon compte"
product: "Déposer l'objet"
session: "Se connecter"
update:
user: "Mettre à jour mon compte"
product: "Modifier l'objet"
I tried this :
def submit_button(model)
if model == nil
I18n.t('submit.create.%{model}')
else
I18n.t('submit.update.%{model}')
end
end
But it didn't worked and rspec send me that :
Capybara::ElementNotFound: Unable to find button ...
I know that's a syntactical problem, but I don't find how to make this work...
You don't need a helper for that, you can achieve it with plain rails. The only thing you need is to properly order your I18n YAML
After that, you only need to define your submit button like this:
Rails will take the label you need for the button.
You can see some more info about it here
You need the name of the model not the model object itself.
Try the following:
model
must not be nil in a form.The %{} is used in en.yml file when you send a local variable from helper or view.