Post requests exercised as a Get


#1

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.

http://stackoverflow.com/questions/22161132/rails-jquery-sending-get-instead-of-post-request

Thanks


#2

On Wed, Mar 5, 2014 at 1:28 PM, Marcus S. removed_email_address@domain.invalid
wrote:

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)

http://stackoverflow.com/questions/22161132/rails-jquery-sending-get-instead-of-post-request

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

Also, is your markup valid?


Hassan S. ------------------------ removed_email_address@domain.invalid
http://about.me/hassanschroeder
twitter: @hassan


#3

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


#4

On Wed, Mar 5, 2014 at 5:24 PM, Marcus S. removed_email_address@domain.invalid
wrote:

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.

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,

Hassan S. ------------------------ removed_email_address@domain.invalid
http://about.me/hassanschroeder
twitter: @hassan


#5

On Wednesday, March 5, 2014 4:28:54 PM UTC-5, Ruby-Forum.com User wrote:

me out that would be appreciated.

http://stackoverflow.com/questions/22161132/rails-jquery-sending-get-instead-of-post-request

Thanks


Posted via http://www.ruby-forum.com/.

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.