0

Stuck with href when moving content from html.slim to html.erb

slim

a[href="#{service_url(id: @data['service_id'])}"]

Tried few in options in .erb - none worked:

<a href="#{service_url(id: @data['service_id'])}" class=...

<ahref="#{service_url(id: @data['service_id'])}" class= ...

<a [href="#{service_url(id: @data['service_id'])}"] class= ...

<a[href="#{service_url(id: @data['service_id'])}"] class= ...

<a :href="#{service_url(id: @data['service_id'])}" class= ...

I tried converting the code using methods provided here but I'm not getting any output.

Holger Just
  • 52,918
  • 14
  • 115
  • 123
Pandation
  • 77
  • 6

1 Answers1

1

Have you tried this?

<a href="<%= service_url(id: @data['service_id']) %>" class=...

The automatic string substitution that slim gives you (with the #{var} syntax) is not available in ERB, so you need to use explicit ERB output tags.

DannyB
  • 12,810
  • 5
  • 55
  • 65
  • Thank @DannyB, that helped. There is another one I am struggling with: `type: t("element_names.#{@data['consultancy']}"))` . I tried: `<%= type: t("element_names.<%=@data['consultancy']%>")%>` and `<% t("element_names.@data['consultancy']")%>` , but looks like it isn't the right way. – Pandation Jan 18 '19 at 13:57
  • I suggest you read a little about slim and a little about ERB, it will eliminate most of the guesswork. I am guessing `type` is generating an HTML `` tag when the slim is evaluated? In ERB, you explicitly write your HTML, and just use ERB tags when you want Embedded Ruby: `<%= t(...) %>`. See [this ERB tags SO question](https://stackoverflow.com/questions/7996695/what-is-the-difference-between-and-in-erb-in-rails) – DannyB Jan 18 '19 at 14:07