Post requests exercised as a Get

Hello, I've been stuck on an issue for a few days now and I haven't been able to find any help online (asked multiple questions on stackoverflow). I'm not sure what to do anymore.

Basically, I have a model 'competition' that allows users to attend it. The user can click 'attend' or 'withdraw' and change their status. it used to work, but my javascript was messed up and I'm not sure how to fix it. If anyone could take a look at the question and hopefully help me out that would be appreciated.

Thanks

it used to work, but my javascript was messed up

Perhaps you could use `git bisect` to find where it was "messed up" (or at least go back to before that happened and redo your changes working forward)

javascript - Rails JQuery sending GET instead of POST request - Stack Overflow

or alternatively answer the question on your SO post about whether you're getting any JavaScript errors.

Also, is your markup valid?

The only response in the console before I click on withdraw is:

event.returnValue is deprecated. Please use the standard event.preventDefault() instead

I tried to go back to then (I have everything on github), but I was unsuccessful in getting it to run. Even if I revert to a previous commit, it still fails. Not sure what to do now though

The only response in the console before I click on withdraw is:

event.returnValue is deprecated. Please use the standard event.preventDefault() instead

I tried to go back to then (I have everything on github), but I was unsuccessful in getting it to run. Even if I revert to a previous commit, it still fails. Not sure what to do now though

You don't have a commit where this runs properly at all? If that's so, look at your environment. Perhaps you inadvertently updated a JS library since then? Or added a conflicting gem?

Worst case, start with a clean Rails installation and copy in your tests and code a bit at a time.

Good luck,

The message you’re getting about event.returnValue is a warning, it shouldn’t be causing your problem. This is basic, but you didn’t show your gemfile, I’m assuming you have the gem ‘jquery-rails’ listed. Also, it should be a relatively current version as the older versions had an issue with this. Finally, if there are any jquery files in your assets/javascripts folder, you should delete them. I’m covering these bases only because it sounds like you had an older app that was working and were forced to update it.

Other than that, I would follow Hassan’s recommendation and rebuild. Links are not really intended to be used to pass a post, so Rails has basically rigged it by using javascript to generate a form and submit it. IMO, it’s not a great architecture. If javascript is disabled or there are errors, it defaults to sending it as a get. You may want to consider using button_to instead of link_to, or you could also change your route to “match ‘withdraw’, via: [:get, :post]” to catch both actions.