Save 36% for Black Friday! Learn more

New Discussion

Notifications

You’re not receiving notifications from this thread.

Use the helper methods that are declared in controller and has default params in view spec ?

1
Rails

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 !

Controller methods are not available in the view unless you expose them with helper_method :sort_column

Join the discussion
Create an account Log in