Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation within controller #25

Open
viniciusnz opened this issue Jun 15, 2012 · 2 comments
Open

Translation within controller #25

viniciusnz opened this issue Jun 15, 2012 · 2 comments

Comments

@viniciusnz
Copy link

Hi guys!

First thanks for the awesome gem!

Translation within the controller is failing for me:

file routes.rb

resources :rec_products do
  get 'add', :on => :member
end

on view this works fine:

add_rec_product_url(rec_product)

where rec_product is an instance variable

On the controller, when calling

Rails.application.routes.url_helpers.add_rec_product_url(rec_product)

I get

"NoMethodError: undefined method `add_rec_product_pt_url' for #<ActionView::Base:0xcbd039c>" 

Sorry, I know this is no support group, but is there any way to get the translated url_helpers to work on controllers.

Note I tried these:

Thanks, best,

@francesc
Copy link
Owner

Did you try:

Rails.application.routes.url_helpers.add_rec_product_pt_url(rec_product)

As the gem only aliases regular routes without locale to current locale on the views helper, it's not a real route app (unless you pass it as an option to have all of them).

@viniciusnz
Copy link
Author

Hi Francesc, you're the best!

It does really work. I actually implemented:

Rails.application.routes.url_helpers.send("add_rec_product_#{I18n.locale}_path",rec_product)

and it works! Sorry, I didn't know I had to pass any options so that the gem creates aliases for non regular routes, just for the record, what would that option be?

Thanks! Best,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants