我想从我的currencies控制器重定向到我的markets控制器,将当前货币作为参数传递(市场has_many货币)。 我想做这样的事情:

  redirect_to markets_show_url(id: @currency.market.id, currency: @currency)

如何正确完成?

===============>>#1 票数: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)

网址将是

http://example.com/markets/your_id?currency=YOUR_CURRENCY

===============>>#2 票数: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动作。

  ask by octavian translate from so

未解决问题?本站智能推荐: