我有模型:
class Board < ActiveRecord::Base
belongs_to :user
validates :name, presence: true, uniqueness: {scope: :user_id}
validates :user, presence: true
def to_param
"#{user.username}/#{name}"
end
end
在#create 操作中,我想将用户重定向到:
redirect_to @board
因此,joe
对于拥有boardname
董事会的用户,它将重定向到:/joe/boardname
。取而代之的是,它重定向到/boards/joe/boardname
. 知道为什么吗?
在我的路线中,我有:
resources :boards, except: [:new, :show]
get '/new' => 'boards#new', as: 'new_board'
get '/:username/:name' => 'boards#show', as: 'user_board'