Use Angular variable in Rails link_to

I use Angularjs in some parts of my Rails application, which works great. But I am wondering how to use the Angular value inside link_to.

Here is my pseudo code:

%table %tr{"ng-repeat" => "book in books"} %td {{book.title}} %td= link_to "Show", book_url({{book.id}}) 

This gives me an error:

 syntax error, unexpected '}', expecting tASSOC 

This may also be related to the HAML causing the error, but how can I send the identifier to link_to?

+6
source share
4 answers

Instead of "link_to", I can of course use a regular link:

 %a{href: 'books/{{book.id}}'} 'Show' 
+2
source

This worked for me:

 <li ng-repeat="deal in deals"> <%= link_to 'show,'#','ng-href' => "#{deals_path()}/{{deal.id}}" %> </li> 
+4
source

You cannot do this, I'm afraid. I also think that Rails is quoting the ID that you are passing, but if not, you can always use the original value:

 %td= link_to "Show", book_url('{{book.id}}') 
0
source

It works great:

 = link_to 'Show', URI::unescape(books_path('{{book._id}}')) 
0
source

Source: https://habr.com/ru/post/945596/


All Articles