我收到此错误
“错误的参数数量(给定0,预期为1)”
但是如果我在控制器或范围内运行pry
我可以看到参数并且它们正在被传入。我已经到处搜索但是无法弄清楚为什么会发生这种情况。
控制器
def create
if Conversation.between(params[:sender_id], params[:recipient_id]).present?
@conversation = Conversation.between(params[:sender_id],
params[:recipient_id]).first
else
@conversation = Conversation.create!(conversation_params)
end
end
模型
scope :between, -> (sender_id, recipient_id) { where(sender_id: sender_id, recipient_id: recipient_id).or.where(sender_id: recipient_id, recipient_id: sender_id) }
就像我说的,如果我在任何一个地方撬开,我都能看到它们在那里并且它们被传入。也许它与我的范围有关?
答案 0 :(得分:0)
您使用的是Rails 5吗?如果你是,我认为你错过了import sys, pygame
pygame.init()
width, height = 700, 700
screen = pygame.display.set_mode((width, height), pygame.RESIZABLE)
clock = pygame.time.Clock()
FPS = 120
x1 = 0
y1 = 0
xmb1 = False
xmf1 = False
ymb1 = False
ymf1 = False
squareh = 50
squarew = 50
squares = 3
BLACK = (0,0,0)
WHITE = (255,255,255)
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.display.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
xmb1 = True
if event.key == pygame.K_RIGHT:
xmf1 = True
if event.key == pygame.K_UP:
ymb1 = True
if event.key == pygame.K_DOWN:
ymf1 = True
elif event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
xmb1 = False
if event.key == pygame.K_RIGHT:
xmf1 = False
if event.key == pygame.K_UP:
ymb1 = False
if event.key == pygame.K_DOWN:
ymf1 = False
if x1 == 0:
xmb1 = False
if y1 == 0:
ymb1 = False
if x1 == width - squarew:
xmfl = False
if y1 == height - squareh:
ymf1 == False
if xmb1:
x1 -= squares
if xmf1:
x1 += squares
if ymb1:
y1 -= squares
if ymf1:
y1 += squares
screen.fill(BLACK)
pygame.draw.rect(screen, WHITE, (x1, y1, squareh, squarew), 0)
pygame.display.flip()
clock.tick(FPS)
的争论。如果您将范围更改为此类型,它应该可以正常工作。你的第二个where子句应该是or
的参数。
or
scope :between, -> (sender_id, recipient_id) { where(sender_id: sender_id, recipient_id: recipient_id).or(where(sender_id: recipient_id, recipient_id: sender_id)) }
答案 1 :(得分:0)
试试这个:
scope :between, ->(params) {where(sender_id: params[:sender_id], recipient_id: params[:recipient_id]).or.where(sender_id: params[:recipient_id], recipient_id: params[:sender_id])
然后你必须用:
来调用它 Conversation.between( { sender_id: params[:sender_id], recipient_id: params[:recipient_id]).present?