我已經在我的控制下鍵/值對應該是最後一個參數嗎?語法錯誤在用戶控制器Ruby on Rails的
@user_party = UserParty.request(:start_date => params[:start_date], :start_time => params[:start_time]), current_user, @friend)
但我得到的錯誤:語法錯誤,意外 '',期待=> ... AMS [:START_TIME] CURRENT_USER,@friend)...^
我的全控制器
def create
if params[:user_party] && params[:user_].has_key?(:friend_id)
@friend = User.find(params[:user_party][:friend_id])
@user_party = Userparty.request({:start_date => params[:start_date], :start_time => params[:start_time]}, current_user, @friend)
respond_to do |format|
if @user_party.new_record?
format.html do
flash[:error] = "There was a problem creating that friend request."
redirect_to user_path(@friend)
end
format.json {render json: @user_party.to_json}
else
format.html do
flash[:success] = "Userparty request sent"
redirect_to user_path(@friend)
end
format.json {render json: @user_party.to_json}
end
end
else
flash[:error] = "party required"
redirect_to root_path
end
end
和我user_party.rb是像這樣
def self.request(start_date, start_time, user1, user2)
transaction do
party1 = UserParty.create!(start_date: start_date, start_time: start_time, user: user1, friend: user2, state: 'pending')
party2 = UserParty.create!(start_date: start_date, start_time: start_time, user: user2, friend: user1, state: 'requested')
end
結束
你會如何正確寫入?在此先感謝
這就是爲什麼在最後使用哈希樣式選項是一個好主意。 – tadman 2014-12-02 17:58:33