Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take Hash with options inside Array in #url_for #9599

Merged
merged 1 commit into from
Nov 15, 2013
Merged

Take Hash with options inside Array in #url_for #9599

merged 1 commit into from
Nov 15, 2013

Conversation

ognevsky
Copy link
Contributor

@ognevsky ognevsky commented Mar 7, 2013

Allows you to code like this:

= link_to 'Edit', [:edit, @post, { author_id: current_user.id }]

@ognevsky
Copy link
Contributor Author

ognevsky commented Mar 7, 2013

cc @drogus

@carlosantoniodasilva
Copy link
Member

Needs tests and a changelog entry.

@senny
Copy link
Member

senny commented Mar 8, 2013

great patch 👍 looking forward to it!

@senny
Copy link
Member

senny commented Mar 8, 2013

/cc @bjoernbur

@bjoernbur
Copy link

thanks for this patch...

@ognevsky
Copy link
Contributor Author

ognevsky commented Mar 8, 2013

I'm done with tests and a changelog entry.

cc @carlosantoniodasilva @senny


controller = kls.new
assert_equal("http://www.basecamphq.com/admin/posts/new?param=value",
controller.send(:url_for, [:new, :admin, :post, { :param => 'value' }])

Choose a reason for hiding this comment

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

Please use 1.9 style hash.

@ognevsky
Copy link
Contributor Author

ognevsky commented Mar 8, 2013

Done.

cc @carlosantoniodasilva

@egilburg
Copy link
Contributor

egilburg commented Mar 8, 2013

+1 for the behaviour, but why extract_options! is needed for the Array case but not for the basic else case? Could perhaps the fix better live inside the polymorphic_path/polymorphic_url methods themselves?

@ognevsky
Copy link
Contributor Author

ognevsky commented Mar 8, 2013

@egilburg there are a lot of else cases, not only arrays. So, it would break a lot of tests and code (actually, I tried it in my first attempt).

Look, polymorphic helpers already have this functionality, you can path url options as the second param (as I do with extract_options!).

You can use it like polymorphic_path [:some, :path, :here], param: 'value', the problem is that you can't set this param without polymorphic_path invocation, so you can't actually write link_to post.title, [:edit, :admin, @post], param: 'value'.

I hope I've cleared this.

@pixeltrix
Copy link
Contributor

@egilburg doing it in polymorphic_path was tried in #7259 and rejected because of clashes with form_for behaviour.

@josevalim are you still 👎 on this behavior ?

@ognevsky ognevsky mentioned this pull request May 3, 2013
@senny
Copy link
Member

senny commented Jun 15, 2013

@josevalim ping

@ognevsky
Copy link
Contributor Author

@senny ping

@senny
Copy link
Member

senny commented Oct 16, 2013

@ognevsky we need to wait for @josevalim to jump in.

@ognevsky
Copy link
Contributor Author

@senny ok, let's wait.

@josevalim
Copy link
Contributor

The issue here is what is going to be considered the form object in form_for if the last element is a hash. Can a hash be a form object today? If so, how this patch affect form_for? If we have those semantics clear, I don't see any problem with this patch.

@pixeltrix
Copy link
Contributor

@ognevsky if you can add tests for form_for with this behaviour and rebase so it'll merge cleanly then I think we have a 👍

@ognevsky
Copy link
Contributor Author

@josevalim @pixeltrix sorry for the long wait.

Jose, this patch doesn't affect to form_for, because it uses polymorphic_path here: https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/form_helper.rb#L453, not the url_for.

So, I don't change form_for behavior.

@ognevsky
Copy link
Contributor Author

@josevalim @pixeltrix I've rebased and updated this request.
I'll add a record to changelog before the merge, it changes very often.

@chancancode
Copy link
Member

@ognevsky Looks like there's failure https://travis-ci.org/rails/rails/jobs/13876911#L3127

@ognevsky
Copy link
Contributor Author

@chancancode oops, I'll fix it in the morning

@ognevsky
Copy link
Contributor Author

Fixed. I've added this failing spec to the commit accidentally, it should never pass (because form_for doesn't have this features)

@pixeltrix
Copy link
Contributor

@ognevsky can you add a CHANGELOG entry and squash your commits - then I'll merge it.

@ognevsky
Copy link
Contributor Author

@pixeltrix I'm ready

pixeltrix added a commit that referenced this pull request Nov 15, 2013
Take Hash with options inside Array in #url_for
@pixeltrix pixeltrix merged commit ce06d57 into rails:master Nov 15, 2013
@pixeltrix
Copy link
Contributor

@ognevsky thanks!

@nathanbertram
Copy link

You da man!

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.

9 participants