简体   繁体   中英

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:

在此处输入图片说明

This is the html.erb code:

<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? Normally link_to related helpers are already available to view. So, no need to add them with helper_method. However if you are redefining those methods somewhere (eg. LinkPrivilege module) , they won't work normally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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