title: How do I redirect back to a page I'm currently on?
body: <p>In my users photo album page they see photos they have uploaded and each photo has a 'make default' link on it.
  When the user clicks <code>make default</code>, then the id of the photo is stored in the <code>photo_id</code> column of my profiles table.</p>
  
  <p>The issue is redirecting them back to:</p>
  
  <pre><code>localhost:3000/settings/photo_gallery/:id
  </code></pre>
  
  <p>Is there a way I can redirect back to the photo album using the id of the photo that has just been set as the default? Can Rails find what album I want to redirect to just by looking at the id of a photo, as a photo belongs to a photo album, and a photo album has many photos?</p>
  
  <p>I have the following tables in my database:</p>
  
  <ul>
  <li>User(s): has one profile, has many PhotoAlbums</li>
  <li>Profile(s): belongs to user</li>
  <li>PhotoAlbum(s): belongs to user, has many photos</li>
  <li>Photo(s): belongs to PhotoAlbum</li>
  </ul>
  
  <p>Controller action:</p>
  
  <pre><code>def set_default_profile_photo
  
    photo = Profile.find_by_user_id(current_user.id)
    photo.photo_id = params[:photo_id]
    photo.save
  
    redirect_to "**HERE IS WHERE I'D LIKE TO REDIRECT TO THE PHOTOALBUM THE PHOTO IS IN**"
    flash[:success] = "Default photo set!"
  
  end
  </code></pre>
  
  <p>My routes:</p>
  
  <pre><code>                    users GET    /users(.:format)                                  {:action=&gt;"index", :controller=&gt;"users"}
                            POST   /users(.:format)                                  {:action=&gt;"create", :controller=&gt;"users"}
                   new_user GET    /users/new(.:format)                              {:action=&gt;"new", :controller=&gt;"users"}
                  edit_user GET    /users/:id/edit(.:format)                         {:action=&gt;"edit", :controller=&gt;"users"}
                       user GET    /users/:id(.:format)                              {:action=&gt;"show", :controller=&gt;"users"}
                            PUT    /users/:id(.:format)                              {:action=&gt;"update", :controller=&gt;"users"}
                            DELETE /users/:id(.:format)                              {:action=&gt;"destroy", :controller=&gt;"users"}
                   sessions GET    /sessions(.:format)                               {:action=&gt;"index", :controller=&gt;"sessions"}
                            POST   /sessions(.:format)                               {:action=&gt;"create", :controller=&gt;"sessions"}
                new_session GET    /sessions/new(.:format)                           {:action=&gt;"new", :controller=&gt;"sessions"}
               edit_session GET    /sessions/:id/edit(.:format)                      {:action=&gt;"edit", :controller=&gt;"sessions"}
                    session GET    /sessions/:id(.:format)                           {:action=&gt;"show", :controller=&gt;"sessions"}
                            PUT    /sessions/:id(.:format)                           {:action=&gt;"update", :controller=&gt;"sessions"}
                            DELETE /sessions/:id(.:format)                           {:action=&gt;"destroy", :controller=&gt;"sessions"}
                  passwords GET    /passwords(.:format)                              {:action=&gt;"index", :controller=&gt;"passwords"}
                            POST   /passwords(.:format)                              {:action=&gt;"create", :controller=&gt;"passwords"}
               new_password GET    /passwords/new(.:format)                          {:action=&gt;"new", :controller=&gt;"passwords"}
              edit_password GET    /passwords/:id/edit(.:format)                     {:action=&gt;"edit", :controller=&gt;"passwords"}
                   password GET    /passwords/:id(.:format)                          {:action=&gt;"show", :controller=&gt;"passwords"}
                            PUT    /passwords/:id(.:format)                          {:action=&gt;"update", :controller=&gt;"passwords"}
                            DELETE /passwords/:id(.:format)                          {:action=&gt;"destroy", :controller=&gt;"passwords"}
                   profiles GET    /profiles(.:format)                               {:action=&gt;"index", :controller=&gt;"profiles"}
                            POST   /profiles(.:format)                               {:action=&gt;"create", :controller=&gt;"profiles"}
                new_profile GET    /profiles/new(.:format)                           {:action=&gt;"new", :controller=&gt;"profiles"}
               edit_profile GET    /profiles/:id/edit(.:format)                      {:action=&gt;"edit", :controller=&gt;"profiles"}
                    profile GET    /profiles/:id(.:format)                           {:action=&gt;"show", :controller=&gt;"profiles"}
                            PUT    /profiles/:id(.:format)                           {:action=&gt;"update", :controller=&gt;"profiles"}
                            DELETE /profiles/:id(.:format)                           {:action=&gt;"destroy", :controller=&gt;"profiles"}
                     emails GET    /emails(.:format)                                 {:action=&gt;"index", :controller=&gt;"emails"}
                            POST   /emails(.:format)                                 {:action=&gt;"create", :controller=&gt;"emails"}
                  new_email GET    /emails/new(.:format)                             {:action=&gt;"new", :controller=&gt;"emails"}
                 edit_email GET    /emails/:id/edit(.:format)                        {:action=&gt;"edit", :controller=&gt;"emails"}
                      email GET    /emails/:id(.:format)                             {:action=&gt;"show", :controller=&gt;"emails"}
                            PUT    /emails/:id(.:format)                             {:action=&gt;"update", :controller=&gt;"emails"}
                            DELETE /emails/:id(.:format)                             {:action=&gt;"destroy", :controller=&gt;"emails"}
                       root        /                                                 {:controller=&gt;"users", :action=&gt;"new"}
                    success        /success(.:format)                                {:action=&gt;"success", :controller=&gt;"users"}
                      login        /login(.:format)                                  {:action=&gt;"new", :controller=&gt;"sessions"}
                     logout        /logout(.:format)                                 {:action=&gt;"destroy", :controller=&gt;"sessions"}
             reset_password        /reset_password(.:format)                         {:action=&gt;"new", :controller=&gt;"passwords"}
         setup_new_password        /setup_new_password(.:format)                     {:action=&gt;"edit", :controller=&gt;"passwords"}
                   settings        /settings(.:format)                               {:action=&gt;"settings", :controller=&gt;"users"}
           settings_account        /settings/account(.:format)                       {:controller=&gt;"users", :action=&gt;"account"}
      settings_edit_profile        /settings/edit_profile(.:format)                  {:controller=&gt;"profiles", :action=&gt;"edit_profile"}
                                   /:username(.:format)                              {:controller=&gt;"users", :action=&gt;"show"}
            change_password        /change_password(.:format)                        {:action=&gt;"change_password", :controller=&gt;"users"}
  profile_photo_set_default        /profile_photo/set_default(.:format)              {:controller=&gt;"photo_albums", :action=&gt;"set_default_profile_photo"}
    album_photo_set_default        /album_photo/set_default(.:format)                {:controller=&gt;"photo_albums", :action=&gt;"set_default_album_photo"}
               photo_albums GET    /settings/photo_gallery(.:format)                 {:action=&gt;"index", :controller=&gt;"photo_albums"}
                            POST   /settings/photo_gallery(.:format)                 {:action=&gt;"create", :controller=&gt;"photo_albums"}
            new_photo_album GET    /settings/photo_gallery/new(.:format)             {:action=&gt;"new", :controller=&gt;"photo_albums"}
           edit_photo_album GET    /settings/photo_gallery/:id/edit(.:format)        {:action=&gt;"edit", :controller=&gt;"photo_albums"}
                photo_album GET    /settings/photo_gallery/:id(.:format)             {:action=&gt;"show", :controller=&gt;"photo_albums"}
                            PUT    /settings/photo_gallery/:id(.:format)             {:action=&gt;"update", :controller=&gt;"photo_albums"}
                            DELETE /settings/photo_gallery/:id(.:format)             {:action=&gt;"destroy", :controller=&gt;"photo_albums"}
                     photos GET    /settings/photo_gallery/photos(.:format)          {:action=&gt;"index", :controller=&gt;"photos"}
                            POST   /settings/photo_gallery/photos(.:format)          {:action=&gt;"create", :controller=&gt;"photos"}
                  new_photo GET    /settings/photo_gallery/photos/new(.:format)      {:action=&gt;"new", :controller=&gt;"photos"}
                 edit_photo GET    /settings/photo_gallery/photos/:id/edit(.:format) {:action=&gt;"edit", :controller=&gt;"photos"}
                      photo GET    /settings/photo_gallery/photos/:id(.:format)      {:action=&gt;"show", :controller=&gt;"photos"}
                            PUT    /settings/photo_gallery/photos/:id(.:format)      {:action=&gt;"update", :controller=&gt;"photos"}
                            DELETE /settings/photo_gallery/photos/:id(.:format)      {:action=&gt;"destroy", :controller=&gt;"photos"}
  </code></pre>