簡體   English   中英

使用haml中的link_to傳遞參數

[英]passing parameters using link_to in haml

%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']

以上只是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

路徑(show_path)是/ system_accounts /:id

如果id為23,我如何將參數id傳遞給控制器​​和link / system_accounts / 23,例如:。

這將鏈接到該帳戶的正確顯示頁面:

= link_to account.id, account

您始終可以向路徑顯式添加任何其他參數:

= link_to account.id, account_path(:id => account.id, :foo => "bar")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM