我如何重定向回目前我正在使用的网页? [英] How do I redirect back to a page I'm currently on?

查看:130
本文介绍了我如何重定向回目前我正在使用的网页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的用户相册页面上,他们看到了他们上传的照片,每张照片上都有一个默认链接。
当用户点击 make default 时,照片的ID存储在 photo_id 列中我的个人资料表。

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 make default, then the id of the photo is stored in the photo_id column of my profiles table.

问题是将它们重新导向:

The issue is redirecting them back to:

localhost:3000/settings/photo_gallery/:id

有没有办法让我重新回到使用刚刚设置为默认照片的ID的相册? Can Rails通过查看照片的ID可以找到我想要重定向的相册,因为照片属于相册,而相册有很多照片?

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?

在我的数据库中有以下表格:

I have the following tables in my database:


  • 用户:有一个配置文件,有很多照片相册

  • 个人资料:属于用户

  • 照片相册:属于用户,拥有多张照片

  • 照片s):属于PhotoAlbum

  • User(s): has one profile, has many PhotoAlbums
  • Profile(s): belongs to user
  • PhotoAlbum(s): belongs to user, has many photos
  • Photo(s): belongs to PhotoAlbum

控制器动作:

Controller action:

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

我的路线:

                    users GET    /users(.:format)                                  {:action=>"index", :controller=>"users"}
                          POST   /users(.:format)                                  {:action=>"create", :controller=>"users"}
                 new_user GET    /users/new(.:format)                              {:action=>"new", :controller=>"users"}
                edit_user GET    /users/:id/edit(.:format)                         {:action=>"edit", :controller=>"users"}
                     user GET    /users/:id(.:format)                              {:action=>"show", :controller=>"users"}
                          PUT    /users/:id(.:format)                              {:action=>"update", :controller=>"users"}
                          DELETE /users/:id(.:format)                              {:action=>"destroy", :controller=>"users"}
                 sessions GET    /sessions(.:format)                               {:action=>"index", :controller=>"sessions"}
                          POST   /sessions(.:format)                               {:action=>"create", :controller=>"sessions"}
              new_session GET    /sessions/new(.:format)                           {:action=>"new", :controller=>"sessions"}
             edit_session GET    /sessions/:id/edit(.:format)                      {:action=>"edit", :controller=>"sessions"}
                  session GET    /sessions/:id(.:format)                           {:action=>"show", :controller=>"sessions"}
                          PUT    /sessions/:id(.:format)                           {:action=>"update", :controller=>"sessions"}
                          DELETE /sessions/:id(.:format)                           {:action=>"destroy", :controller=>"sessions"}
                passwords GET    /passwords(.:format)                              {:action=>"index", :controller=>"passwords"}
                          POST   /passwords(.:format)                              {:action=>"create", :controller=>"passwords"}
             new_password GET    /passwords/new(.:format)                          {:action=>"new", :controller=>"passwords"}
            edit_password GET    /passwords/:id/edit(.:format)                     {:action=>"edit", :controller=>"passwords"}
                 password GET    /passwords/:id(.:format)                          {:action=>"show", :controller=>"passwords"}
                          PUT    /passwords/:id(.:format)                          {:action=>"update", :controller=>"passwords"}
                          DELETE /passwords/:id(.:format)                          {:action=>"destroy", :controller=>"passwords"}
                 profiles GET    /profiles(.:format)                               {:action=>"index", :controller=>"profiles"}
                          POST   /profiles(.:format)                               {:action=>"create", :controller=>"profiles"}
              new_profile GET    /profiles/new(.:format)                           {:action=>"new", :controller=>"profiles"}
             edit_profile GET    /profiles/:id/edit(.:format)                      {:action=>"edit", :controller=>"profiles"}
                  profile GET    /profiles/:id(.:format)                           {:action=>"show", :controller=>"profiles"}
                          PUT    /profiles/:id(.:format)                           {:action=>"update", :controller=>"profiles"}
                          DELETE /profiles/:id(.:format)                           {:action=>"destroy", :controller=>"profiles"}
                   emails GET    /emails(.:format)                                 {:action=>"index", :controller=>"emails"}
                          POST   /emails(.:format)                                 {:action=>"create", :controller=>"emails"}
                new_email GET    /emails/new(.:format)                             {:action=>"new", :controller=>"emails"}
               edit_email GET    /emails/:id/edit(.:format)                        {:action=>"edit", :controller=>"emails"}
                    email GET    /emails/:id(.:format)                             {:action=>"show", :controller=>"emails"}
                          PUT    /emails/:id(.:format)                             {:action=>"update", :controller=>"emails"}
                          DELETE /emails/:id(.:format)                             {:action=>"destroy", :controller=>"emails"}
                     root        /                                                 {:controller=>"users", :action=>"new"}
                  success        /success(.:format)                                {:action=>"success", :controller=>"users"}
                    login        /login(.:format)                                  {:action=>"new", :controller=>"sessions"}
                   logout        /logout(.:format)                                 {:action=>"destroy", :controller=>"sessions"}
           reset_password        /reset_password(.:format)                         {:action=>"new", :controller=>"passwords"}
       setup_new_password        /setup_new_password(.:format)                     {:action=>"edit", :controller=>"passwords"}
                 settings        /settings(.:format)                               {:action=>"settings", :controller=>"users"}
         settings_account        /settings/account(.:format)                       {:controller=>"users", :action=>"account"}
    settings_edit_profile        /settings/edit_profile(.:format)                  {:controller=>"profiles", :action=>"edit_profile"}
                                 /:username(.:format)                              {:controller=>"users", :action=>"show"}
          change_password        /change_password(.:format)                        {:action=>"change_password", :controller=>"users"}
profile_photo_set_default        /profile_photo/set_default(.:format)              {:controller=>"photo_albums", :action=>"set_default_profile_photo"}
  album_photo_set_default        /album_photo/set_default(.:format)                {:controller=>"photo_albums", :action=>"set_default_album_photo"}
             photo_albums GET    /settings/photo_gallery(.:format)                 {:action=>"index", :controller=>"photo_albums"}
                          POST   /settings/photo_gallery(.:format)                 {:action=>"create", :controller=>"photo_albums"}
          new_photo_album GET    /settings/photo_gallery/new(.:format)             {:action=>"new", :controller=>"photo_albums"}
         edit_photo_album GET    /settings/photo_gallery/:id/edit(.:format)        {:action=>"edit", :controller=>"photo_albums"}
              photo_album GET    /settings/photo_gallery/:id(.:format)             {:action=>"show", :controller=>"photo_albums"}
                          PUT    /settings/photo_gallery/:id(.:format)             {:action=>"update", :controller=>"photo_albums"}
                          DELETE /settings/photo_gallery/:id(.:format)             {:action=>"destroy", :controller=>"photo_albums"}
                   photos GET    /settings/photo_gallery/photos(.:format)          {:action=>"index", :controller=>"photos"}
                          POST   /settings/photo_gallery/photos(.:format)          {:action=>"create", :controller=>"photos"}
                new_photo GET    /settings/photo_gallery/photos/new(.:format)      {:action=>"new", :controller=>"photos"}
               edit_photo GET    /settings/photo_gallery/photos/:id/edit(.:format) {:action=>"edit", :controller=>"photos"}
                    photo GET    /settings/photo_gallery/photos/:id(.:format)      {:action=>"show", :controller=>"photos"}
                          PUT    /settings/photo_gallery/photos/:id(.:format)      {:action=>"update", :controller=>"photos"}
                          DELETE /settings/photo_gallery/photos/:id(.:format)      {:action=>"destroy", :controller=>"photos"}


推荐答案

redirect_to:back 想看看这是否是正确的选择
http://api.rubyonrails .ORG /文件/ ActionPack的/ lib目录/ action_contro ller / metal / redirecting_rb.html

redirect_to :back worked for me but I want to see if this was the right choice http://api.rubyonrails.org/files/actionpack/lib/action_controller/metal/redirecting_rb.html

这篇关于我如何重定向回目前我正在使用的网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆