Skip to content

Conversation

DmytroVasin
Copy link
Contributor

@DmytroVasin DmytroVasin commented Apr 10, 2017

Steps to reproduce

Hi!
I'm using rails 5.1.0.rc1 and faced with next unexpected behaviour.

According to documentation I can set remote: true on select element like next:

<%= select_tag( "user_id", some_collection, ..., data: { remote: true, url: users_path } %>

And in this case everything will work.

But actually I can remove url

Expected behavior

When we use jquery_ujs and use $.ajax function:
This ajax function provides default value for url if it is not specified.

url (default: The current page)
Type: String
A string containing the URL to which the request is sent.

Actual behavior

Currently if I remove url option from select_tag I will receive an error:

rails-ujs.js:189 Uncaught TypeError: Cannot read property 'indexOf' of null
    at prepareOptions (rails-ujs.js:189)
    at Rails.ajax (rails-ujs.js:161)
    at HTMLSelectElement.Rails.handleRemote (rails-ujs.js:536)
    at HTMLDocument.<anonymous> (rails-ujs.js:137)
    at jQuery.fn.init.triggerNative (settings.js:96)
    at Object.<anonymous> (data-remote.js:435)
    at Test.run (qunit.js:1303)
    at qunit.js:1463
    at process (qunit.js:1016)
    at qunit.js:186

System configuration

Rails version:
5.1.0.rc1
Ruby version:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]

Other Information

Maybe you had reasons not to do this.

Thanks.

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @eileencodes (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@maclover7
Copy link
Contributor

@DmytroVasin Would you be able to add a test for this behavior?

@DmytroVasin
Copy link
Contributor Author

Yes, i will

Copy link
Member

@rafaelfranca rafaelfranca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you squash your commits?

@DmytroVasin DmytroVasin force-pushed the rails-ujs-default-url branch from da82bc5 to dc8ddea Compare April 11, 2017 03:58
@DmytroVasin
Copy link
Contributor Author

@rafaelfranca Done

@rafaelfranca rafaelfranca merged commit acc5a55 into rails:master Apr 11, 2017
rafaelfranca added a commit that referenced this pull request Apr 11, 2017
rails-ujs: missing default url for ajax requests.
@rafaelfranca
Copy link
Member

Backported c7493fe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants