0

我是一个初学者,我很难弄清楚这一点。

另外,我不知道测试这段代码的方法,因为我正在使用 ActiveStorage 并且给我带来麻烦的方法连接到使用 S3 存储桶内的 URi 的 AWS API,而我的本地文件是,好吧,本地的,所以我真的被困住了。

我在我的一个控制器中编写了一个方法,它接受一个参数(url),虽然我相信我正确地发送了它(从一个按钮)并传递了正确的参数,但它一直告诉我ArgumentError (wrong number of arguments (given 0, expected 1)):

它是这样的:

在我的模型中:

def transcript_text
        @transcript_text = Aws::TranscribeService::Client.new(region: 'eu-west-1')
end

def self.new_job_name
        SecureRandom.urlsafe_base64
end

里面的方法transcript_controller.rb(请忽略错误处理,这也可能是错误的):

def request_transcription(url)
    resp = @transcript_text.start_transcription_job( { settings: { show_speaker_labels: false, max_speaker_labels: 1, channel_identification: false}, language_code: "es-ES", media: { media_file_uri: url }, transcription_job_name: @transcript_text.new_job_name } )
    if resp
      format.html { redirect_to @transcript, notice: 'Transcript job started.' }
    else
      format.html { redirect_to @transcript, alert: 'Something didn't go as planned'}
    end
end

最后,在我看来:

<% url = @transcript.audio.service_url.to_s.split("?").first %>
<%= button_to 'Start transcribing', {:controller => "transcripts", :action => "request_transcription", :url => url } , { :method => :post }  %>

@transcript.audio.service_url.to_s.split("?").first获取我想要在 S3 存储桶中转录的文件的 uri。


所以我的理由是,如果我按下那个按钮,它应该将url作为参数发送到transcript_controller#request_transcription,它接受它并使其工作。

我想要什么:我想transcript_controller#request_transcription使用 AWS Transcribe 开始转录工作。然后,我将通过 de aws CLI 检查是否确实如此,然后继续进行。

我得到了什么:让ArgumentError (wrong number of arguments (given 0, expected 1)):我发疯的悲伤。

我在服务器日志中看到了什么:

2019-09-15T16:33:47.927780+00:00 app[web.1]: I, [2019-09-15T16:33:47.927649 #4]  INFO -- : [b23d8f2a-fade-424b-8e21-6b532c5fd470] Started POST "/transcripts/request_transcription?url=https%3A%2F%2F[REDACTED].s3.eu-west-1.amazonaws.com%2F0d4mjj10zgdll7roxkn06rhrhmw9" for 185.79.22.122 at 2019-09-15 16:33:47 +0000
    2019-09-15T16:33:47.929108+00:00 app[web.1]: I, [2019-09-15T16:33:47.929029 #4]  INFO -- : [b23d8f2a-fade-424b-8e21-6b532c5fd470] Processing by TranscriptsController#request_transcription as HTML
    2019-09-15T16:33:47.929195+00:00 app[web.1]: I, [2019-09-15T16:33:47.929132 #4]  INFO -- : [b23d8f2a-fade-424b-8e21-6b532c5fd470]   Parameters: {"authenticity_token"=>"OKDuS9Lu6Y1nv0vgo50qagRNbLAysuqbkDb495zO4FryikWeexYVa+0uTht+Eevw3uUqJ+jA6mibsamcwcWX+A==", "url"=>"https://[REDACTED].s3.eu-west-1.amazonaws.com/0d4mjj10zgdll7roxkn06rhrhmw9"}
    2019-09-15T16:33:47.950168+00:00 app[web.1]: D, [2019-09-15T16:33:47.950019 #4] DEBUG -- : [b23d8f2a-fade-424b-8e21-6b532c5fd470]   User Load (3.8ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 2], ["LIMIT", 1]]
    2019-09-15T16:33:47.965636+00:00 app[web.1]: I, [2019-09-15T16:33:47.965509 #4]  INFO -- : [b23d8f2a-fade-424b-8e21-6b532c5fd470] Completed 500 Internal Server Error in 36ms (ActiveRecord: 3.8ms | Allocations: 1338)
    2019-09-15T16:33:47.971644+00:00 app[web.1]: F, [2019-09-15T16:33:47.971537 #4] FATAL -- : [b23d8f2a-fade-424b-8e21-6b532c5fd470]
    2019-09-15T16:33:47.971648+00:00 app[web.1]: [b23d8f2a-fade-424b-8e21-6b532c5fd470] ArgumentError (wrong number of arguments (given 0, expected 1)):
    2019-09-15T16:33:47.971651+00:00 app[web.1]: [b23d8f2a-fade-424b-8e21-6b532c5fd470]
    2019-09-15T16:33:47.971653+00:00 app[web.1]: [b23d8f2a-fade-424b-8e21-6b532c5fd470] app/controllers/transcripts_controller.rb:70:in `request_transcription'

除了这些代码行中可能出现严重错误的所有其他事情之外,您能帮我url在 request_transcription 方法中找到它吗?提前致谢

4

2 回答 2

0

尝试改变:

<%= button_to 'Start transcribing', {:controller => "transcripts", :action => "request_transcription", :url => url } , { :method => :post }  %>

至:

<%= button_to 'Invite a user', your_action_path(url: url), method: :post, remote: true %>

请检查您的操作路径rails routes | grep request_transcription

于 2019-09-15T16:47:49.657 回答
0

我发现发生了什么。

在这种情况下,request_transcription 方法不应期望任何参数。

所以而不是

def request_transcription(url)
.
.
end

应该是

def request_transcription
.
.
end

那解决了它。谢谢大家的解答和关心!

于 2019-09-15T19:51:32.200 回答