1

こんにちは、リモート レール フォームからいくつかのパラメーターを抽出しようとしています。問題のパラメーターは event_id です。

私のコントローラーでは、次のことを行いました。

def create
  @availability = Availability.new(params[:availability])
  @exclude = Availability.where(:event_id => params[:event_id]).select(:user_id).pluck(:user_id)
  @players = User.where('team_id = ? and id NOT IN (?)', current_user[:team_id], @exclude).all
  @event = Event.where('id = ?', params[:event_id])

  respond_to do |format|
    if @availability.save
      format.html { redirect_to @availability, :notice => 'Availability was successfully created.' }
      format.js { @availabilities = Availability.all }
    else
      format.html { render :action => "new" }
      format.json { render :json => @availability.errors, :status => :unprocessable_entity }
    end
  end
end

そして、このリクエストを起動するアクションは次のとおりです。

%li= button_to 'Add', availabilities_path(:availability => {:team_id => @event.team_id, :user_id => user, :event_id => @event.id }), :remote => true, :method => :post, :class => 'button tiny success', :disable_with => 'Add'

問題は、モデルが event_id を検出しないのはなぜですか?

 Started POST "/availabilities?availability%5Bevent_id%5D=75&availability%5Bteam_id%5D=1&availability%5Buser_id%5D=54" for 124.168.81.54 at 2013-02-12 08:48:42 +0100
Processing by AvailabilitiesController#create as JS
  Parameters: {"authenticity_token"=>"sebpDgAPPmK8q9024vrhN4eEQT7vZLr+pa5XdSicAMc=", "availability"=>{"event_id"=>"75", "team_id"=>"1", "user_id"=>"54"}}
  User Load (1.5ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 38 LIMIT 1
   (0.8ms)  SELECT user_id, user_id FROM "availabilities" WHERE "availabilities"."event_id" IS NULL
  User Load (1.3ms)  SELECT "users".* FROM "users" WHERE (team_id = 1 and id NOT IN (NULL))
   (0.4ms)  BEGIN
  Availability Exists (0.9ms)  SELECT 1 AS one FROM "availabilities" WHERE ("availabilities"."user_id" = 54 AND "availabilities"."event_id" = 75) LIMIT 1
  SQL (1.8ms)  INSERT INTO "availabilities" ("available", "comment", "created_at", "event_id", "team_id", "unique_id", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id"  [["available", nil], ["comment", nil], ["created_at", Tue, 12 Feb 2013 18:48:42 EST +11:00], ["event_id", 75], ["team_id", 1], ["unique_id", nil], ["updated_at", Tue, 12 Feb 2013 18:48:42 EST +11:00], ["user_id", 54]]
   (19.4ms)  COMMIT
  Availability Load (0.9ms)  SELECT "availabilities".* FROM "availabilities" 
  Event Load (0.9ms)  SELECT "events".* FROM "events" WHERE (id = NULL)
  Rendered events/_progress_bar.html.haml (8.6ms)
  Rendered availabilities/create.js.erb (11.1ms)
Completed 500 Internal Server Error in 100ms
4

1 に答える 1

4

event_idparams[:availability][:event_id]はないのでparams[:event_id]

于 2013-02-12T08:05:55.727 に答える