我想从我的currencies
控制器重定向到我的markets
控制器,将当前货币作为参数(市场has_many
种货币)传递。我想做这样的事情:
redirect_to markets_show_url(id: @currency.market.id, currency: @currency)
如何正确完成?
答案 0 :(得分:1)
在config / routes.rb中定义路由
例如
get "markets/:id" => "markets#show", as: :markets_show
在您的控制器中调用
redirect_to markets_show_url(id: @currency.market.id, currency: @currency.currency_name)
网址将
答案 1 :(得分:1)
redirect_to market_url(@currency.market, currency_id: @currency.id)
在markets
的控制器中: -
def show
@market = Market.find(params[:id])
@currency = Currency.find(params[:currency_id])
end
作为市场has_many
货币,当前currency
currency_id
应作为参数传递,以便在market
控制器show
操作中获取当前货币