Ruby on Rails中的Link_to

时间:2015-07-27 06:25:07

标签: html ruby-on-rails ruby erb link-to

我需要在表格中返回搜索结果,当用户点击所需结果时,会将他带到另一个页面。问题是当我将link_to方法添加到表中时,它显示为空:

enter image description here

这是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>

这是我的控制者:

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

当我删除链接时:

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

显示结果。我不明白,请帮我解决这个问题。

1 个答案:

答案 0 :(得分:1)

LinkPrivilege模块有什么作用?通常,link_to相关帮助程序已可供查看。因此,无需使用helper_method添加它们。但是,如果要在某处重新定义这些方法(例如LinkPrivilege模块),它们将无法正常工作。