0

I have a project with the following:

controller: patient/edit

 def edit
   if current_user.nil?
   redirect_to new_user_session_path
 else
   @states = State.all
   @display_dashboard = true
   @patient
   @foo = 1
 end
end

view patient/edit

<%= @patient.inspect %>
<%= @states.inspect %>
<%= @foo.nil? %>

I run byebug on the edit action and @patient has a value, so does @states. However, I can't see @patient on the view. Any ideas? I'm baffled.

4
  • Your edit action is returning @patient? are you setting @patient in a before_action? Commented Dec 23, 2014 at 18:49
  • before_action :set_patient, only: [:show,:edit,:update,:destroy,:dashboard,:allergies,:occupations, :information, :revisions] Commented Dec 23, 2014 at 18:51
  • my before_action allows for :edit, which references @patient Commented Dec 23, 2014 at 18:52
  • remove @patient from your edit action, and see if that changes anything if it is set in the before_action, then it already exists, and unless you are doing something with it (IE modifying it) no need to reference it in the edit action Commented Dec 23, 2014 at 18:56

1 Answer 1

1

@patient doesn't have a value, clearly. If it has a value in the controller action and you've verified this, then you're "emptying" it somewhere in the views.

Change the @patient.inspect to @patient.nil? or @patient.blank? and see if true is displayed.

If you're absolutely certain that the controller value isn't showing up, then do this:

@states = 1

And see if 1 shows up on the view for @states

Perhaps it's some other action altogether.

Sign up to request clarification or add additional context in comments.

4 Comments

@patient already has a value within the class. I only put it there to assure there was a value passing through the action. It does indeed have a value
i've updated the question. i've included @foo. On the view, @foo shows up as nil, yet @states has a value. Could there be something else in the controller I'm missing?
you're right, it still shows as the same value, not 1. We use knockoutjs but I didn't think that could affect a new instance variable i put in the action. I'm still unable to find where it's coming from
It ended up being a variable that was drawn from another action (not edit) and that action was not included in the :before_action

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.