加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 使用haml中的link_to传递参数

发布时间:2020-12-17 01:47:00 所属栏目:百科 来源:网络整理
导读:%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 #
%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")

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读