Ask A Question

Notifications

You’re not receiving notifications from this thread.

Collection and Vars in Controller are different than what's rendered in View

Lauren B asked in General

I'm having a really odd issue and have tried tons of things, but just cannot figure out why this is happening and how to change it.

I have a collection of resources that I render on an index page in a table via partial. The controller action is index, the view is named index. The page has been working correctly on its own.

I needed to add a way to filter based on the fiscal year associated with the resource. Initially I set up a tiny little form at the top of the index view with a dropdown to select the year with a button that hits the index action again but with params for the selected fy. I added code to the index action check for the fiscal year id in the params. (If there are no params, it will use the current fiscal year).

Here's where the odd things started happening. Using pry (this is all in my dev env), and even using print statements, I have verified that the code in the controller successfully gets the fy params, queries the resources, and returns a set filtered for the correct year. I pass the fiscal year resource and this collection to the view. However, the view renders a different set of resources (always for the most recent fiscal year) no matter what I do. I do set the most recent fiscal year to be used in cases when there are no fy params, but it still doesn't make any sense that I can step through each line in the controller action using Pry and verify that the collection is using a year other than the most recent fy. The view renders the most recent fy regardless of what the controller results are.

Even more odd is that I used some puts to print out the values to my terminal (inline with the server logs about the requests and pages rendered). The puts results show what I expect -- a collection filtered to a certain year. But then the page is rendered with the same incorrect data as before.

I have stopped and restarted the server. I have cleared all cookies. I have deleted the server pid and cached files in the temp directory. I even thought that maybe I wasn't re-rendering the page so I set up a different route and controller action to handle the fiscal year form and redirect to the index action with the params... but the results are always the same.

Any thoughts? (and thank you!)

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.