sei-ec-remote / project-2-issues

1 stars 0 forks source link

JSON not posting (to my db) when I click button #222

Closed nabbott98 closed 2 years ago

nabbott98 commented 2 years ago

What's the problem you're trying to solve?

For the routes I have pulling data from NASA's api I want to be able to send the json to my db when I click a button if the user likes the picture

Post any code you think might be relevant (one fenced block per file)

        <button type="button" class="btn btn-success" action="/apods" method="POST" data="{{apod}}" redirect="/apods">Add to 'The Galaxy'</button>

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

No error, does not redirect

What is your best guess as to the source of the problem?

I don't fully grasp how to link a button with data already on the page

What things have you already tried to solve the problem?

I have console.log ed the button with no success, I have added a redirect to the button to make sure that the button works

Paste a link to your repository here

http://localhost:3000/apods/random

scarletpuma commented 2 years ago

You have both of your actions trying to run at the same time, so you're going to want to make a form with the button inside so that you can separate the actions. You can see where Timm did that here: https://git.generalassemb.ly/sei-ec-remote/monster-fruits/blob/version4/views/comment.liquid#L8

nabbott98 commented 2 years ago

Maybe I didn't explain this, but what the page does is call Nasa's api and the page displays that Json, what i'd like the button to do is to trigger a post request send the Json that is displayed on the page as the body

nabbott98 commented 2 years ago

Would making a form do that? Is there a way to make it autofill the form and not display it on the screen?

nabbott98 commented 2 years ago

I was able to use a form and hide it and fill the value with my model. whatever I want