Escaping Link to

I am iterating over a @posts and my eex can display

<%= post.website.domain %>/users/<%= post.user.slug %>/posts/<%= post.slug %>

becomes

website.com/users/niccolox/posts/post-slug-here-1

thats ok

but, when I put this long eex url in a simple href

<a href="<%= post.website.domain %>/users/niccolox/posts/<%= post.id %>"><%= post.title %></a>

becomes (wrong)

http://local.website.com:4000/posts/website.com/users/niccolox/posts/fpost-slug-here-1

I know can make custom Router Helpers, but is there a way to escape the href in eex ?

Look at the generated sources, there is no http://local.website.com:4000/. Your browser only augments it because your href is relative. Use a schema and it work as you expect.

2 Likes

No need to make your own custom router helpers, you can just use router helpers:

Router.Helpers.user_post_path(conn, :show, user_slug, post_slug)

Now this is assuming you have something like this setup in your routes:

resources "/users", UserController do
  resources "/posts", PostController
end
2 Likes

ok, thanks, adding the link schema i.e http fixed it

:muscle:

thanks, I had this already

I should of exposed more

I am adding a third host/domain arg for a multi site cross domain linking solution

I saw dailydrip do some vids on extending actions and routes for a 3rd arg or I could use the host in the router, but I am exploring Forward in router.ex

thanks for the time today