ruby on rails - Passing a hash to i18n translation -


i'm in proccess of creating notification system. system should notify user changes in models, ie .yml file

ru:   notifications:     task: "new task named %{notifiable.task_name}"     order: "new order price %{notifiable.price}" 

you understand have associations user has_many notification , notification has_one(polymorphic) notifiable. so, understand order hasn't attribute task_name , task hasn't attribute price. how can pass hash i18n or implement logic way?

oh ok understood that!

please consider code below:

# making hash def serialized_message_object   attr_hash = {}   @user.attribute_names.each { |attr_name| attr_hash[('user_' + attr_name).to_sym] = @user[attr_name] }   @user.attribute_names.each { |attr_name| attr_hash[('notifiable_' + attr_name).to_sym] = @notifiable[attr_name] }   attr_hash  end  # call i18n i18n.t('notifications.' + message_type, serialized_message_object)  # i18n ru:   notifications:     task: "new task named %{notifiable_task_name}"     order: "new order price %{notifiable_price}"