module SimpleForm::MagicSubmit
Constants
- VERSION
Public Instance Methods
Private Instance Methods
bound_to_model?()
click to toggle source
# File lib/simple_form/magic_submit.rb, line 26 def bound_to_model? # if its a string means that its bound to a model.. but if its a symbol its not... self.object_name.is_a?(String)# || self.object.present? end
controller_scope()
click to toggle source
# File lib/simple_form/magic_submit.rb, line 35 def controller_scope # falls to default if the model isn't tied to a model return "default" unless bound_to_model? template.controller.params[:controller].gsub('/', '.') end
main_class(options = {})
click to toggle source
# File lib/simple_form/magic_submit.rb, line 31 def main_class(options = {}) options.fetch(:destructive, false) ? 'btn-destructive' : 'btn-primary' end
object_scope()
click to toggle source
# File lib/simple_form/magic_submit.rb, line 42 def object_scope # returns empty string if no model is found to prevent exception return "" unless bound_to_model? self.object.class.model_name.i18n_key.to_s end
translate_key(key = nil)
click to toggle source
# File lib/simple_form/magic_submit.rb, line 49 def translate_key(key = nil) if bound_to_model? key ||= self.object.errors.count > 0 ? :retry : :submit I18n.t("simple_form.magic_submit.#{controller_scope}.#{object_scope}.#{lookup_action}.#{key}", default: [ :"simple_form.magic_submit.#{controller_scope}.#{lookup_action}.#{key}", :"simple_form.magic_submit.default.#{lookup_action}.#{key}", :"helpers.submit.#{lookup_action}" ], model: self.object.class.model_name.human.titlecase ).html_safe else # we have no model errors... so we test if the post is get or already posted key ||= template.request.get? ? :submit : :retry I18n.t("simple_form.magic_submit.#{controller_scope}.#{object_scope}.#{lookup_action}.#{key}", default: [ :"simple_form.magic_submit.#{controller_scope}.#{lookup_action}.#{key}", :"simple_form.magic_submit.default.#{lookup_action}.#{key}", :"helpers.submit.#{lookup_action}" ]).html_safe end end