I'm trying to get the variable "response.data.uri" from my jQuery to a rails controller, but it isn't working. I can get to the rails controller but the variable isnt there.
jQuery:
function responseCallbackHandler(response) {
switch (response.status) {
case 201:
$.ajax({ url: '#{addbank_bankaccts_path}',
type: 'POST',
beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', '#{form_authenticity_token}')},
dataType: "json",
data: 'account_uri=' + response.data.uri
success: function(response) {
// successfully executed the controller method
}
});
break;
}
}
routes.rb:
post "/bankaccts/new" => 'bankaccts#addbank'
controller:
class BankacctsController < ApplicationController
def addbank
@uri = (params['customer_uri'])
@id = (params['id'])
@auri = (params['account_uri'])
# all equal nil ^
redirect_to root_url
end
params['account_uri']
, have you tried that?params
hash in your controller to make sure data is coming through and also check ifresponse.data.uri
has your expected value in the browser console.