0

更新アクションの後にshowアクションにリダイレクトする必要がある単純なアプリに取り組んでいます。

私はショーのためにこのルートを持っています。

match '/user/:fullname' => 'items#show'

これでこのコントローラーができました。

@user = User.find_by_fullname(params[:fullname])

ただし、ユーザーの更新方法の後、

def update
  if @user.update_attributes(params[:user])
    format.html { redirect_to @user } # Don't need to pass parameters here.
  else
    format.html { render action: 'edit' }
  end
end

それは私をショーアクションの元のフォーマットにリダイレクトします:

sampleapp.dev/users/1

完全名であるroutes.rbで指定した形式を使用して、アクションを表示するようにリダイレクトするにはどうすればよいですか?

sampleapp.dev/users/johndoe
4

1 に答える 1

2

この行を次のように変更します。

match '/user/:fullname' => 'items#show', :as => :custom_show_item

次に、リダイレクトを次のように変更します。

redirect_to custom_show_item_path(:fullname => @user.fullname)
于 2012-09-17T05:28:23.867 に答える