Hallo allerseits Ich habe ein Problem beim Einrichten meiner App. Es verwendet die shopify-API, und im Wesentlichen werden einige Daten über eine Ansicht abgerufen und an die Steuerung gesendet, aber ich habe Probleme, sie an eine andere Methode im Controller zu übergeben, um die API zum Speichern der Daten zu verwenden.Rails Ajax Call: JSON an separate Controller-Methode übergeben
Hier ist mein Code:
-Controller
class BuilderController < ShopifyApp::AuthenticatedController
def index
urlval = request.fullpath
@urlCheck = urlval.split('/').last
end
def show
url = request.fullpath
@urlID = url.split('/').last
@customers = ShopifyAPI::Customer.search(query: "id:"+ @urlID)
#need to get a way to retrieve the ajax call info here to pass into the update
end
def updateCustomer(notes)
@customers.each do |cus|
cus.note = notes
cus.save()
end
end
def new
notes = params[:notes]
updateCustomer(notes)
render json: notes
end
end
Ansicht
<button id="test">TEST</button>
<script>
var butt = document.getElementById('test');
butt.addEventListener("click",function(){
$.ajax({
url: "/builder/new",
type: "GET",
data: {
"notes": [
"test",
"test2"
]
},
success: function(data,text,xhr) {
console.log(text);
console.log(xhr);
console.log(data);
alert('successfully');
},
error: function(data,error){
console.log(data);
console.log(error);
alert("help");
}
});
});
</script>
die Aktionen Umsetzung meiner Updatecustomer Methode zu sein? – dpat