【问题标题】:rails parameters not found未找到导轨参数
【发布时间】:2015-04-21 22:02:44
【问题描述】:

我正在开发使用条纹支付的应用程序。我的应用程序中有计划和订阅模型。计划有很多订阅,订阅属于 t 计划。在计划索引页面上,我有计划列表,用户可以点击任何计划

<td><%=link_to plan.name, new_subscription_path(:plan_id => plan.id) %></td>

在我的订阅控制器中我有这个

def new
 @plan = Plan.find(params[:plan_id])
 @subscription = @plan.subscriptions.new
end

def create
 @plan = Plan.find(params[:plan_id])
 @subscription = @plan.subscriptions.new(subscription_params)

 respond_to do |format|
  if @subscription.save
    format.html { redirect_to @subscription, notice: 'Subscription was successfully created.' }
    format.json { render :show, status: :created, location: @subscription }
  else
    format.html { render :new }
    format.json { render json: @subscription.errors, status: :unprocessable_entity }
  end
 end
end

我正在尝试根据特定计划建立订阅,但我收到此错误

Couldn't find Plan with 'id'= 

【问题讨论】:

  • 你能添加你的 config/routes.rb 吗?
  • 资源:计划,资源:订阅

标签: ruby ruby-on-rails-3


【解决方案1】:

你应该更新你的 config/routes.rb 看起来像:

resources :plans do
  resources :subscriptions
end

稍后在您的模板中,您应该使用new_plan_subscription_path,例如:

<td><%=link_to plan.name, new_plan_subscription_path(:plan_id => plan.id) %></td>

这应该有帮助!

祝你好运!

【讨论】:

  • 作为注释这样做你可以使用&lt;%=link_to plan.name, new_plan_subscription_path(plan) %&gt;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-10
  • 1970-01-01
相关资源
最近更新 更多