1

I need pass in charge attributes in model contract_url(contract) I have following code in model CheckoutService:

delegate :url_helpers, to: 'Rails.application.routes'

def contract_url(cont)
    url_helpers.contract_url(cont)
  end

In charge_attributes i need set url for attribute secureUrl, for example:

charge_attributes 
{
  secureReturnUrl: contract_url(contract)
}

I get an error:

ActionController::UrlGenerationError: No route matches {:action=>"show", :controller=>"contracts", :locale=>#<Contract id: 13, ..} missing required keys: [:id]

rake routes:

contract GET (/:locale)/contracts/:id(.:format) contracts#show {:locale=>/en|fr/} PATCH (/:locale)/contracts/:id(.:format)

If i call this url helper in controller or view work correct. How pass current locale in url in model? Thank you.

Stefan Hansch
  • 1,550
  • 4
  • 22
  • 55

1 Answers1

1

Add parameter :locale to url. I18n.locale return current locale.

contact_url(contact, locale: I18n.locale)
Alex Kojin
  • 5,044
  • 2
  • 29
  • 31
  • ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true – Stefan Hansch Nov 19 '16 at 09:04
  • Read this http://stackoverflow.com/questions/7219732/missing-host-to-link-to-please-provide-host-parameter-or-set-default-url-optio – Alex Kojin Nov 19 '16 at 10:16