Post requests exercised as a Get

30 views
Skip to first unread message

Marcus Smith

unread,
Mar 5, 2014, 4:28:54 PM3/5/14
to rubyonra...@googlegroups.com
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

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

Hassan Schroeder

unread,
Mar 5, 2014, 5:41:35 PM3/5/14
to rubyonrails-talk
On Wed, Mar 5, 2014 at 1:28 PM, Marcus Smith <li...@ruby-forum.com> 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 Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

Marcus Smith

unread,
Mar 5, 2014, 8:25:09 PM3/5/14
to rubyonra...@googlegroups.com
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

Marcus Smith

unread,
Mar 5, 2014, 8:24:48 PM3/5/14
to rubyonra...@googlegroups.com
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

Hassan Schroeder

unread,
Mar 6, 2014, 1:12:12 PM3/6/14
to rubyonrails-talk
On Wed, Mar 5, 2014 at 5:24 PM, Marcus Smith <li...@ruby-forum.com> 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,

mike

unread,
Mar 6, 2014, 8:27:25 PM3/6/14
to rubyonra...@googlegroups.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.
Reply all
Reply to author
Forward
0 new messages