缺少Param(向另一个控制器发送请求)

时间:2015-03-26 22:57:57

标签: ruby-on-rails

我得到的错误是:

ActionController::ParameterMissing in CampaignsController#create
param is missing or the value is empty: campaign

我的路线:

resources :users, except: [:destroy] do
  post 'add_email', on: :member
end

resources :campaigns, only: [:create, :destroy, :index] do
  get 'status'
end

我在广告系列中显示的模式#index

<%= form_for add_email_user_path(@user) do |f| %>
 <%= f.email_field :email, placeholder: 'Your email address', class: 'input-lg form-control', autofocus: true %>
 <%= f.button 'Continue', class: 'btn btn-success', 'data-disable-with' => "Saving <i class='fa fa-spinner fa-spin'></i>".html_safe %>
<% end %>

campaigns_controller:

def index
  @campaigns = current_user.campaigns.all
  @new_campaign = current_user.campaigns.new
  @user = current_user
end

private

def campaign_params
  params.require(:campaign).permit(:keyword)
end

users_controller:

def add_email
  @user = User.find(params[:id])
  if @user.update_attributes(setup_params)
    redirect_to campaigns_path, notice: 'Thank you for adding your email!'
  else
    redirect_to :back, alert: 'Unable to save your email'
  end
end

private

def setup_params
  params.require(:user).permit(:email)
end

所以我要做的是允许用户添加他们的电子邮件(在广告系列索引中显示模式,但由于某种原因,我得到了广告系列参数丢失。广告系列属于用户。

0 个答案:

没有答案