0

I'm a begginer and I'm having trouble figuring this one out.

Also, I don't know of a way of testing this piece of code because I'm using ActiveStorage and the method that is giving me trouble connects to an AWS API which uses the URi inside an S3 bucket, while my local files are, well, local, so I'm really stuck.

I've written a method in one of my controllers which accepts one argument (url) and, although I believe I'm sending it properly (from a button) and passing the correct params, it keeps telling me ArgumentError (wrong number of arguments (given 0, expected 1)):

It goes as follows:

In my model:

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

and

def self.new_job_name
        SecureRandom.urlsafe_base64
end

The method inside transcript_controller.rb (please disregard the error handling, which is probably wrong too):

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

and finally, in my views:

<% 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 gets the uri of the file I want transcribed inside my S3 bucket.


So my reasoning is that if I press that button, it should send the url as a param to the transcript_controller#request_transcription, which accepts it and puts it to work.

What do I want: I want transcript_controller#request_transcription to start a transcription job with AWS Transcribe. I'll then check via de aws CLI if actually did, and move along from that.

What am I getting: that sad ArgumentError (wrong number of arguments (given 0, expected 1)): that is driving me crazy.

What do I see in my server logs:

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'

Apart from all the other things that might be horribly wrong in these lines of code, can you please help me get that url inside the request_transcription method? Thanks in advance

brobert
  • 43
  • 4

2 Answers2

0

try to change:

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

to:

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

please check your action path in rails routes | grep request_transcription

leafeve
  • 150
  • 2
  • 8
  • It still does the same and ends up in the same error: `[fe9dca60-403b-4ebb-bf87-5402e3563f44] ArgumentError (wrong number of arguments (given 0, expected 1)):` My routes are OK I believe: `transcripts_request_transcription POST /transcripts/request_transcription(.:format) transcripts#request_transcription` – brobert Sep 15 '19 at 17:00
0

I found what happens.

request_transcription method should not, in this case, expect any arguments.

So instead of

def request_transcription(url)
.
.
end

it should have been

def request_transcription
.
.
end

That solved it. Thanks everyone for the answers and for caring!

brobert
  • 43
  • 4