KEYUR DONDA
KEYUR DONDA

Reputation: 1

How can I insert and variable in between 2 strings in ruby on rails

My code:

@pageb=2

<a data-remote="true" href="/?activities_page= @pageb &partial=true&render=activities"> >> </a>

URL I want:

http://localhost:9292/?activities_page=   2   &partial=true&render=activities

URL I get:

http://localhost:9292/?activities_page=   %20@pageb%20   &partial=true&render=activities

Upvotes: 0

Views: 90

Answers (1)

spickermann
spickermann

Reputation: 106792

I would argue that you should never build URLs by string concatenation. That is error-prone and you might end up with invalid URLs easily. Ruby on Rails has helper methods to build and escape URLs properly.

You didn't provide much context but in your case, something like this might work:

<%= link_to ' >> ', 
    root_path(activities_page: @pageb, partial: true, render: 'activities'),
    data: { remote: true } %>

Upvotes: 1

Related Questions