Submit button helper with I18n.t

前端 未结 3 754
孤街浪徒
孤街浪徒 2020-12-18 05:21

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 :



        
3条回答
  •  星月不相逢
    2020-12-18 05:57

    def submit_button(model)
      if model == nil
        I18n.t("submit.create.#{model}")
      else
        I18n.t("submit.update.#{model}")
      end
    end
    

    The %{} is used in en.yml file when you send a local variable from helper or view.

提交回复
热议问题