Save 36% for Black Friday! Learn more

Uzval

Joined

50 Experience
0 Lessons Completed
0 Questions Solved

Activity

Here's the problem:
I have a Controller (say ExampleController) which has a method "sort_column" and it has the following code :
Example.column_names.include?(params[:sort]) ? params[:sort] : 'title'
which says that, In the "Example" model, if you find any column names that include the params[sort], whitelist them.
I have declared this method "sort_column" as a helper method in my controller by declaring
helper_method :sort_column

Now, my question is that, upon render of index page, i sorted the table by default to have asc order. If i try to test the index.html.erb, which renders by having the sort_column as 'title', i am blocked with an error saying this

Failure/Error: direction = (column == sort_column) && (sort_direction == 'asc' ? 'desc' : 'asc')

 ActionView::Template::Error:
   undefined local variable or method `sort_column' for #<#<Class:0x00007fd4f085c380>:0x00007fd4eb195c90>

Hitting my head from a couple of days with this error !

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.