Rails Link_to 块中的简单锚点
Rails simple Anchor within a Link_to Block
关于如何在 rails 中的常规 link 上添加锚标记,我已经看到了一百个 post,但没有一个是关于使用 [= =29=] 做,等等。我知道我遗漏了一些愚蠢的东西,但是如果我想始终跳转到 # 的 div ID 上的锚点,那么在下面的代码块中锚点格式应该是什么样子选卡?非常感谢任何帮助...
index.html.erb(将 link 转到 'show' 页面)
<%= link_to post do %>
<%= image_tag(post.postimage_url, :alt => "logo", :style=>"box-shadow: 0px 0px 2px #ddd; margin-bottom: 8px; width: 100%; max-height: 140px;") %>
<% end %>
我已经尝试了 <%= link_to post, anchor: "selected-card" do %> 和其他一百万件事,但似乎无法正常工作。
Show.html.erb(我的锚 ID 所在的位置):
<div id="selected-card">
some code here
</div>
路线文件:
Rails.application.routes.draw do
devise_for :users
root to: 'visitor_pages#posts'
# root to: 'posts#index'
resources :posts
resources :posts do
member do
get :referred, :references
end
end
end
如果您使用对象代替完整路径,则需要将其与 html 选项一起嵌入数组 (source):
<%= link_to [post, anchor: "selected-card"] do %>
...
<% end %>
<!-- generates <a href="/posts/1#selected-card">...</a> -->
关于如何在 rails 中的常规 link 上添加锚标记,我已经看到了一百个 post,但没有一个是关于使用 [= =29=] 做,等等。我知道我遗漏了一些愚蠢的东西,但是如果我想始终跳转到 # 的 div ID 上的锚点,那么在下面的代码块中锚点格式应该是什么样子选卡?非常感谢任何帮助...
index.html.erb(将 link 转到 'show' 页面)
<%= link_to post do %>
<%= image_tag(post.postimage_url, :alt => "logo", :style=>"box-shadow: 0px 0px 2px #ddd; margin-bottom: 8px; width: 100%; max-height: 140px;") %>
<% end %>
我已经尝试了 <%= link_to post, anchor: "selected-card" do %> 和其他一百万件事,但似乎无法正常工作。
Show.html.erb(我的锚 ID 所在的位置):
<div id="selected-card">
some code here
</div>
路线文件:
Rails.application.routes.draw do
devise_for :users
root to: 'visitor_pages#posts'
# root to: 'posts#index'
resources :posts
resources :posts do
member do
get :referred, :references
end
end
end
如果您使用对象代替完整路径,则需要将其与 html 选项一起嵌入数组 (source):
<%= link_to [post, anchor: "selected-card"] do %>
...
<% end %>
<!-- generates <a href="/posts/1#selected-card">...</a> -->