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

params hash keys #1405

Closed
graudeejs opened this issue Sep 10, 2013 · 7 comments · Fixed by #1470
Closed

params hash keys #1405

graudeejs opened this issue Sep 10, 2013 · 7 comments · Fixed by #1470

Comments

@graudeejs
Copy link
Contributor

If you submit form, all keys in hash are strings

however if you defined

put :edit, :map => '/:id' do
...
end

then id will be symbol in params hash i.e. params[:id]

I propose to extend params so that no matter string or symbol key is request it returns expected value, or at least convert them to string or symbols.

@graudeejs
Copy link
Contributor Author

Example:

{
  "_method"=>"put",
  "authenticity_token"=>  ".....",
  "bookmark"=>
  {
     "title"=>"FreeBSD",
     "url"=>"http://www.freebsd.org/"
  },
 :id=>"6"
}

@namusyaka
Copy link
Contributor

Makes sense.
And string key is not cool.
I want to propose to separate params to two variables.
How about this?

get :foo, :map => "/:id" do
  "id : #{captures[:id]}, query : #{params[:foo]}"
end

# get "/1?foo=bar"
# body #=> "id : 1, query : bar"

This big change will cut the compatibility.

@ujifgc
Copy link
Member

ujifgc commented Sep 18, 2013

So, params would only have real post/get query variables? Seems really unorthodox.

@namusyaka
Copy link
Contributor

Sure, I think this way is not best. But I have no idea...

@Ortuna
Copy link
Member

Ortuna commented Sep 22, 2013

Maybe I'm missing something but I think we're looking for HashWithIndifferentAccess

@ujifgc
Copy link
Member

ujifgc commented Sep 22, 2013

Yeah... A recursive one.

@namusyaka
Copy link
Contributor

Should we use HashWithIndifferentAccess for params?

Ortuna added a commit that referenced this issue Oct 18, 2013
Ortuna added a commit that referenced this issue Oct 18, 2013
- the `params` variable is converted into a HashWithIndifferentAccess
  object
- fixes #1405
Ortuna added a commit that referenced this issue Oct 23, 2013
namusyaka pushed a commit to namusyaka/padrino-framework that referenced this issue Oct 27, 2013
- the `params` variable is converted into a HashWithIndifferentAccess
  object
- fixes padrino#1405

Conflicts:

	padrino-core/lib/padrino-core/application/routing.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants