Question: I'm trying to redirect to the previous page after a user logs in. I am using a bootstrap modal for login/register forms but if someone doesn't have JS enabled on their browser and are taken to the '/login' page, I want to make sure they are redirected to the root url. I know current\_page? does not work with POST requests.

I've tried tons of things so the following code is redirecting correctly from the '/login' page to the root url but I am not being redirected to ':back' when logging in using the bootstrap modal. 

This is from SessionsController: (PS- I have sessions#new/sessions#create as /login in routes)

```
def create
    user = User.find_by(email: params[:email]) 
    if user && user.authenticate(params[:password])
        session[:user_id] = user.id

            if request.path === '/login'
                redirect_to '/'
            else
                redirect_to :back
            end

            flash[:success] = "Logged in."

    else
        flash.now[:danger] = "Email and password did not match. Please try again."
        render :new
    end
end

def destroy
    session[:user_id] = nil
    flash[:success] = "Logged out."
    redirect_to '/'
end

```

Routes.rb:

```
Rails.application.routes.draw do

root to: 'home#home'

resources :users

get '/login', to: 'sessions#new'
post '/login', to: 'sessions#create'
get '/logout', to: 'sessions#destroy'

end

```

Answer: 
I figured it out. I basically create an order variable, name that variable the animal names, and then use that ordered variable to create the chart rather than the animals themselves. Below is the quick process:

Create an order variable

```
data test1; set test;
    temp=_n_;
    char_animal=put(temp,3.);
run;

```

Put your sequence of animals in a list

```
proc sql;
    select distinct quote(animal)
    into: animallist separated by " "
    from test1 order by temp;
quit;

%put &animallist.;

```

In the `axis3` statement, use the macro list in the value statement to "name" the order variable the animal names

```
axis1 label=(f=arial h=1.5 'Time to Death (Hours Post-Exposure)') value=(f=arial h=1) order=(0 to 840 by 120) minor=(n=5) offset=(1,1);
axis2 label=(f=arial h=1.2 j=r 'Group') value=(f=arial h=1);
axis3 label=(f=arial h=1.2 j=c 'Animal') value=(f=arial h=1 &animallist.);
PATTERN1 C=BLACK;

proc gchart data=test1;
  hbar char_animal /group=group nozero nostats sumvar=ttd type=sum
              width=0.4 space=1 raxis=axis1 gaxis=axis2 maxis=axis3;
run; quit;

```

Notice the correct order in the graphic now:

[![enter image description here](https://i.stack.imgur.com/nulm2.png)](https://i.stack.imgur.com/nulm2.png)
I don't think you can get it in the dataset order. (Technically, by the way, this is *ascending* order of the value of Animal - while it goes 'down' it is still considered ascending from the point of view of the proc; see how the ASCENDING/DESCENDING option order things.)

From my understanding, gplot for HBAR allows (default=ascending order of values, ASCENDING=ascending order of bars, DESCENDING=descending order of bars). 

You can use SGPLOT (which has `grouporder=data` option, at least by 9.4). 

```
proc sgplot data=test;
  hbar group/ response=ttd group=animal groupdisplay=cluster grouporder=reversedata;
run;

```

I use `reversedata`, as the ascending/descending thing is flipped in hbars compared to what seems logical, but you can also flip the axis itself if you prefer that (or if reversedata is not available in your version).