简体   繁体   English

Ruby on Rails中的Link_to

[英]Link_to in Ruby on Rails

I have a from where I need to return a search result in a table and when the user clicks on the required result, it takes him to another page. 我有一个从这里需要在表格中返回搜索结果的地方,当用户单击所需的结果时,它将带他到另一个页面。 The problem is when I add the link_to method to the table, it shows empty: 问题是当我将link_to方法添加到表中时,它显示为空:

在此处输入图片说明

This is the html.erb code: 这是html.erb代码:

<div id ="info">
    <% if @guardians_result.nil? or @guardians_result.empty? %>
      <div id="no_result" class="themed_text"><%= t('no_users') %></div>
    <%else%>
      <table align="center" width="100%" cellpadding="1" cellspacing="1" id="listing">
        <tr class="tr-head">
          <td>
            <%= t('sl_no') %>
          </td>
          <td>
            <%= t('name') %>
          </td>

        </tr>
        <% @guardians_result.each_with_index do |guardian,i| %>
          <tr class="tr-<%= cycle('odd', 'even')%>">
            <td class="col-1"><%= i+1 %></td>
            <td class="col-4"><%=  link_to guardian.full_name, :controller => 'parent_wise_fee_payments', :action => 'pay_all_fees', :id => guardian.id%></td>
          </tr>
        <% end %>
      </table>
      <%end%>
   </div>

And this is my controller: 这是我的控制器:

class ParentWiseFeePaymentsController < ApplicationController
  before_filter :login_required
  filter_access_to :all
  before_filter :set_precision
  include LinkPrivilege
  helper_method('link_to','link_to_remote','link_present')

  def index
  end



  def pay_all_fees 
     if params[:id].present?
      id = params[:id]
        @guardian=Guardian.find(id)
        @ward=@guardian.current_ward()

        @siblings=@ward.all_siblings()
    end
  end


 def search_logic #parent search (fees submission)
    query = params[:query]
    @target_action=params[:target_action]
    @target_controller=params[:target_controller]
if (query.length!=0)
        @guardians_result = Guardian.first_name_or_last_name_begins_with query
end
    render :layout => false
  end

When I remove the link: 当我删除链接时:

        <td class="col-4"><%=   guardian.full_name %></td>

It shows the result. 它显示结果。 I don't get it, please help me figure this out. 我不明白,请帮助我解决这个问题。

What does LinkPrivilege module do? LinkPrivilege模块有什么作用? Normally link_to related helpers are already available to view. 通常,link_to相关的帮助者已经可以查看。 So, no need to add them with helper_method. 因此,无需使用helper_method添加它们。 However if you are redefining those methods somewhere (eg. LinkPrivilege module) , they won't work normally. 但是,如果您在某处(例如LinkPrivilege模块)重新定义这些方法,则它们将无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM