7

I'm using Angularjs in parts of my Rails app, which works great. But I'm wondering how to use an Angular value inside a 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 could also have to do with HAML causing the error, but how can I send the ID in the link_to?

1
  • Instead of a "link_to", I can of course use a normal link: %a{href: 'books/{{book.id}}'} 'Show' Commented May 22, 2013 at 18:17

3 Answers 3

4

This worked for me:

<li ng-repeat="deal in deals">
    <%= link_to 'show,'#','ng-href' => "#{deals_path()}/{{deal.id}}" %>
</li>
Sign up to request clarification or add additional context in comments.

3 Comments

Wont anything after the # be treated as a comment and therefore not work?
@Linus: no, the # is inside a string.
Oh yes you're absolutely right, it was just Atom not being able to display the syntax correctly.
3

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

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

Comments

0

It work fine:

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.