通过 link_to(r) do...end 传递参数
Pass parameters through link_to(r) do... end
我的代码循环遍历多个图像。每个图像都是一个 link,我想要的是在那些 link 中传递相同的 url 参数。
<% @render.each_slice(2) do |renders| %>
<div class="row">
<% renders.each do |r| %>
<%= link_to(r) do %>
<div class="col-md-6" align="center" style="margin-bottom: 5em; border-radius: 5px;">
<%= image_tag(r.image) %>
</div>
<% end %>
<% end %>
</div>
<% end %>
我已经尝试了很多方法link_to(r, :link => 'portafolio')。
routes.rb是这样的
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root 'pages#main'
get 'index/' => 'pages#index'
get 'index/see' => 'pages#see'
get 'index/see/:id' => 'pages#show', as: :render
end
为了在 link_to
助手上传递一个块,您必须指定路径,您只是在传递 r
,但那个值是多少?它打印什么?
您可以尝试指定路径,并在内部作为参数 r
值:
<%= link_to some_path(parameter: value_for_r) do %>
<!-- The content wrapped in the link_to -->
<% end %>
指定路径,用r指定id
<%= link_to render_path(r, link: :portafolio, parameter: :value) do %>
<% end %>
我的代码循环遍历多个图像。每个图像都是一个 link,我想要的是在那些 link 中传递相同的 url 参数。
<% @render.each_slice(2) do |renders| %>
<div class="row">
<% renders.each do |r| %>
<%= link_to(r) do %>
<div class="col-md-6" align="center" style="margin-bottom: 5em; border-radius: 5px;">
<%= image_tag(r.image) %>
</div>
<% end %>
<% end %>
</div>
<% end %>
我已经尝试了很多方法link_to(r, :link => 'portafolio')。
routes.rb是这样的
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root 'pages#main'
get 'index/' => 'pages#index'
get 'index/see' => 'pages#see'
get 'index/see/:id' => 'pages#show', as: :render
end
为了在 link_to
助手上传递一个块,您必须指定路径,您只是在传递 r
,但那个值是多少?它打印什么?
您可以尝试指定路径,并在内部作为参数 r
值:
<%= link_to some_path(parameter: value_for_r) do %>
<!-- The content wrapped in the link_to -->
<% end %>
指定路径,用r指定id
<%= link_to render_path(r, link: :portafolio, parameter: :value) do %>
<% end %>