简体   繁体   中英

undefined method in view ruby on rails

I sorted my table following this tutorial http://railscasts.com/episodes/228-sortable-table-columns

I'm getting a undefined method sortable' for #<#<Class:0x00000002f90c48>:0x00000002ba85b8> when i call sortable.

index.html.erb:

<table class="issuesTable">
  <thead>
    <tr>
        <th><%= sortable "title" %></th>
        <th>Desc</th>
        ...

application_helper.rb:

module ApplicationHelper
  def sortable(column, title = nil)
    title ||= column.titleize
    css_class = column == sort_column ? "current #{sort_direction}" : nil
    direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
    link_to title, {:sort => column, :direction => direction}, {:class => css_class}
   end
 end

issues_controller.rb:

# GET /issues
# GET /issues.json
helper_method :sort_column, :sort_direction

def index
  @issues = Issue.order(sort_column + " " + sort_direction)
end

...

private
  def sort_column
    Issue.column_names.include?(params[:sort]) ? params[:sort] : "title"
  end

  def sort_direction
    %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
  end

So, it turned out that the IDE he was using created issues for him and didn't update the helper files, so there was no function in the files.

After saving those files, the code executed perfectly.

So, key to problem was saving the code :P

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