2015-02-04 48 views
-4

我有屬於實際上,當我想編輯我的個人資料我正在重定向到http://localhost:3000/1/profile而不是http://localhost:3000/profile爲什麼用戶的輪廓模型後重定向?這是我的個人資料resource :profile的Rails:一個行動

路線,這是我的個人資料控制器

before_filter :authenticate_user! 

    def show 
    @user = current_user 
    @profile = @user.profile 
    end 

    def update 

    @user = current_user 
    @profile = @user.profile 

    respond_to do |format| 
     if @profile.update(profile_params) 
     flash[:notice] = "profile à été mis à jour!" 
     format.html { redirect_to @profile } 
     else 
     format.html { render action: 'edit' } 
     end 
    end 
    end 

更新

這是配置文件路徑

profile POST     (/:locale)/profile(.:format)        profiles#create {:locale=>/en|fr/} 
       new_profile GET     (/:locale)/profile/new(.:format)       profiles#new {:locale=>/en|fr/} 
       edit_profile GET     (/:locale)/profile/edit(.:format)       profiles#edit {:locale=>/en|fr/} 
          GET     (/:locale)/profile(.:format)        profiles#show {:locale=>/en|fr/} 
          PATCH     (/:locale)/profile(.:format)        profiles#update {:locale=>/en|fr/} 
          PUT     (/:locale)/profile(.:format)        profiles#update {:locale=>/en|fr/} 
          DELETE    (/:locale)/profile(.:format)        profiles#destroy {:locale=>/en|fr/} 
+0

爲什麼我重定向到http:// localhost:3000/1/profile而不是http:// localhost:3000/profile,您甚至在閱讀它之前已將該問題投下來謝謝 – userails

+0

請張貼您的路線.rb和相關模型的片段。 – vpsz

+0

我的個人資料的路線是資源:配置文件和配置文件模式belongs_to的:用戶 \t \t acts_as_taggable_on:技能 \t \t的has_many:profile_languages accepts_nested_attributes_for:profile_languages ...... – userails

回答

0

因爲你正在做的redirect_to @profile你更新行動。這是你會遇到的Rails Magic之一。約定是,只要您使用redirect_to中的對象,它將自動將您重定向到對象show頁面。

+0

所以都建議使用profile_path,而不是因爲我有嘗試它的整個路線它給出了相同的結果 – userails

+0

如何張貼你的路線的結果。在命令行中運行這個'耙routes' – Finks

+0

我使用的資源:配置文件,以便我的節目頁是http://本地主機:3000/profile文件 – userails

0

你不想重定向到@profile對象,而只是profile_path(這是你的奇異資源的途徑之一)。 ProfileController中的操作將處理查找current_user的配置文件對象。

+0

即使我用profile_path我重定向到相同的路線 – userails

+0

IDK,對我的作品有我的主頁:資源:家,只:[:顯示],控制器:'家'。產生輔助home_path,它生成/ home並被路由到HomeController#show。 – vpsz

+0

編輯配置文件時出現問題我沒有重定向到顯示頁面,但是您描述的內容已經適用於我 – userails

相關問題