0

Is there a chance to remove + signs that merges category name that consists of two words?

Generated link looks like :

http://localhost:3000/lv/products?category=Dakšu+iekrāvēji

Between Dakšu and iekrāvēji is the problem, can I just leave with empty space ? Like this:

http://localhost:3000/lv/products?category=Dakšu iekrāvēji

UPDATE

Inside view I have like this.

<%= link_to (categ.name), products_path(:category => categ.name)   %> 

Routes

scope "(:locale)", :locale => /en|lv|ru/ do
   resources :products, :manufacturers, :categories, :news, :ActiveAdmin, :manufacturer_products, :about_us, :contacts, :services
  end

Tnx

1
  • How did you "generate" that link?
    – Mischa
    Sep 12, 2013 at 5:43

2 Answers 2

1

The best way that i use : create a hash of the variables and use the methods to_query and append it to the path.

x = { "a" => "check1+123","b" => "check2" }
x.to_query 

"a=check1%2B123&b=check2" is returned and can be appended to the path.

1

If you use Regex like this, I think it should work

<% temp = link_to (categ.name), products_path(:category => categ.name)   %> 
<% temp.gsub!(/\+/," ") %>
<%= temp %>

what we have done is we will put the URL as a string in a temp variable and then replace the plus sign with a space character as you wanted. In the last step we have put that whole link again to the HTML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.