link_to kommt mit Syntax/Signatur link_to(name = nil, options = nil, html_options = nil, &block)
Das erstellt ein Link-Tag des angegebenen Namens mit einer URL, die durch den Satz von Optionen erstellt wurde.
Signaturen;
link_to(body, url, html_options = {})
# url is a String; you can use URL helpers like
# posts_path
link_to(body, url_options = {}, html_options = {})
# url_options, except :method, is passed to url_for
link_to(options = {}, html_options = {}) do
# name
end
link_to(url, html_options = {}) do
# name
end
Ich werde das gleiche Beispiel aus Ihrer Frage nehmen,
Dieser link_to "Profile", profile_path(@profile)
schafft Pfad;
# => <a href="/profiles/1">Profile</a>
während <%=link_to "show", posts_path(post.id) %>
schafft
# => <a href="/profiles.1">show</a>
Weitere Möglichkeiten entsprechenden Routen zu erstellen sind wie folgt;
link_to "Profile", @profile
# => <a href="/profiles/1">Profile</a>
link_to "Profile", controller: "profiles", action: "show", id: @profile
# => <a href="/profiles/show/1">Profile</a>
Hoffnung könnte dies helfen Ihnen sonst das sehen link_to apidoc
können Sie versuchen, '<% = link_to "show", posts_path (post)%>' –
leider nicht :-( –
funktioniert kann Sie teilen Ihre routes.rb-Datei, Sie müssen post_path (Beitrag) in Ihrer HTML-Datei hinzufügen – tjs7706