Skip to content

Allow body for remote link with method POST #163

Closed
emerleite wants to merge 4 commits intorails:masterfrom
emerleite:master
Closed

Allow body for remote link with method POST #163
emerleite wants to merge 4 commits intorails:masterfrom
emerleite:master

Conversation

@emerleite
Copy link
Contributor

Allow link_to with remote => true for method POST with request body. I needed this in my project for a link inside another form, wich I could not insert a form inside another form. Should be usefull for other people.

Example: <%= link_to "something", path, :remote => true, :method => 'post', "data-body" => "key1=val1&key2=val2" %>

…I needed this in my project for a link inside another form, wich I could not insert a form inside another form. Should be usefull for other people.
@emerleite
Copy link
Contributor Author

Forgot a comment in src/rails.js. Please remove when integrate.

Cheers

@neerajsingh0101
Copy link

Nice work. And thanks for the tests.

I have two comments.

  1. Delete the commented line.

  2. Change element.attr('data-body') to element.attr('data). I find the name 'data-body' highly confusing.

@JangoSteve
Copy link
Member

The data-body attribute name isn't terribly descriptive. What do you guys think of either data-post or data-params?

@emerleite
Copy link
Contributor Author

I've used data-body because it is actualy de body for a POST or PUT request. data-params can be ok too, but I still prefer data-body, because it's more glued to the real purpose, that is send a request body. What do you think? Any other ideas?

@JangoSteve
Copy link
Member

I agree with that part. However, "body" only makes sense in the context that it's for a POST request. But that won't always be the case.

In the more generic context that this is an attribute for a data-remote link, I was thinking we should use a more generic, descriptive attribute. For example, notice that jQuery calls the attribute data, not body. By their definition:

data: Data to be sent to the server. It is converted to a query string, if not already a string. It's appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same key based on the value of the traditional setting (described below).

To me, hands down, it should be called data, to align with jQuery. However, telling people to set the data-data attribute on their remote link would be weird and confusing. Which is why I'm leaning toward data-params; params in the Rails world is more or less synonymous with data in the jQuery world.

I think data-params is more glued to the actual functionality, since the purpose changes depending on the context. But I'm open to other ideas.

@emerleite
Copy link
Contributor Author

Changed to data-params. Really makes more sense.

@JangoSteve
Copy link
Member

Awesome, Emerson, thanks for your patience and work on this new feature :-) Especially with the test coverage, much appreciated. I squashed your commits into 1 and pulled them in. dad6982

@JangoSteve JangoSteve closed this May 21, 2011
@emerleite
Copy link
Contributor Author

;)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants