Skip to content

Take Hash with options inside Array in #url_for#9599

Merged
pixeltrix merged 1 commit into
rails:masterfrom
ognevsky:hash-inside-array-in-url-for
Nov 15, 2013
Merged

Take Hash with options inside Array in #url_for#9599
pixeltrix merged 1 commit into
rails:masterfrom
ognevsky:hash-inside-array-in-url-for

Conversation

@ognevsky

@ognevsky ognevsky commented Mar 7, 2013

Copy link
Copy Markdown
Contributor

Allows you to code like this:

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

@ognevsky

ognevsky commented Mar 7, 2013

Copy link
Copy Markdown
Contributor Author

cc @drogus

@carlosantoniodasilva

Copy link
Copy Markdown
Member

Needs tests and a changelog entry.

@senny

senny commented Mar 8, 2013

Copy link
Copy Markdown
Member

great patch 👍 looking forward to it!

@senny

senny commented Mar 8, 2013

Copy link
Copy Markdown
Member

/cc @bjoernbur

@bjoernbur

Copy link
Copy Markdown

thanks for this patch...

@ognevsky

ognevsky commented Mar 8, 2013

Copy link
Copy Markdown
Contributor Author

I'm done with tests and a changelog entry.

cc @carlosantoniodasilva @senny

Copy link
Copy Markdown
Member

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

ognevsky commented Mar 8, 2013

Copy link
Copy Markdown
Contributor Author

Done.

cc @carlosantoniodasilva

@egilburg

egilburg commented Mar 8, 2013

Copy link
Copy Markdown
Contributor

+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

ognevsky commented Mar 8, 2013

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
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

senny commented Jun 15, 2013

Copy link
Copy Markdown
Member

@josevalim ping

@ognevsky

Copy link
Copy Markdown
Contributor Author

@senny ping

@senny

senny commented Oct 16, 2013

Copy link
Copy Markdown
Member

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

@ognevsky

Copy link
Copy Markdown
Contributor Author

@senny ok, let's wait.

@josevalim

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@ognevsky

Copy link
Copy Markdown
Contributor Author

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

@ognevsky

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@ognevsky

Copy link
Copy Markdown
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
Copy Markdown
Contributor

@ognevsky thanks!

@nathanbertram

Copy link
Copy Markdown

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