%tbody
- @accounts.each do |account|
%tr
%td= link_to account['id'],show_path,{:id => account['id']}
%td= account['name']
%td= account['description']
%td= account['created']
Run Code Online (Sandbox Code Playgroud)
以上只是haml文件的一个片段,在我的控制器中我有以下内容:
def show
# If a system account already exists in session, it was found from a search with the account id
# Otherwise, this is a new search for a system account by the given id
@account = session[:account]
if @account.nil?
Rails.logger.debug { "Querying for the account with id: #{params[:id]}" }
response = query_account(CGI.escape(params[:id]))
@account = JSON.parse(response.body)
end
end
Run Code Online (Sandbox Code Playgroud)
路径(show_path)是/ system_accounts /:id
如果id为23,我如何将参数id传递给控制器和link/system_accounts/23,例如:.
Nik*_*mov 12
这将链接到该帐户的正确显示页面:
= link_to account.id, account
Run Code Online (Sandbox Code Playgroud)
您始终可以向路径显式添加任何其他参数:
= link_to account.id, account_path(:id => account.id, :foo => "bar")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4799 次 |
| 最近记录: |