Shaun Frost Duke Jackson
Shaun Frost Duke Jackson

Reputation: 1266

Double Render Issue

Right let me explain a little in code, I'm trying to get the user to stay on the edit action until the user is completely valid. So far I have the following code in the application controller:

def check_privileges!
  redirect_to "/users/edit" until current_user.valid?
end

registrations_controller.rb

before_filter :check_privileges!, only: [:new, :create]

jobs_controller.rb

before_filter :check_privileges!, only: [:index]

Now when I click on the link to jobs#index it gives me the following error. I cannot see a redirect in jobs#index

AbstractController::DoubleRenderError in JobsController#index

No clue how to sort this, I've tried and return but I cannot figure this out. I've been doing this all day as a user has to complete their profile before they have full access to the application.

Any clues, this is really bugging me now and I have no smart programming friends to help me.

Upvotes: 0

Views: 38

Answers (1)

CDub
CDub

Reputation: 13354

I think what you want is unless not until... until will cause a loop of redirect_to (thus leading to multiple redirects) if the current_user is not valid.

Try:

def check_privileges!
  redirect_to "/users/edit" unless current_user.valid?
end

Upvotes: 1

Related Questions