Skip to content

Add support for camel-casing ActionController::Parameters #931

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

Closed
jcarlson opened this issue Sep 5, 2018 · 1 comment
Closed

Add support for camel-casing ActionController::Parameters #931

jcarlson opened this issue Sep 5, 2018 · 1 comment

Comments

@jcarlson
Copy link
Contributor

jcarlson commented Sep 5, 2018

Steps to reproduce

class MyController < ApplicationController

  def foo
    props = params.permit(:foo_bar, :baz_etc)
    render component: 'foo', props: props, camelize_props: true
  end
end

Note that the given props are not properly camelized when rendered to the React component. This is because React.camelize_props does not recognize ActionController::Parameters as a valid hash and returns it as-is.

Expected behavior

React.camelize_props should camelize instances of ActionController::Parameters.

Actual behavior

React.camelize_props does not camelize instances of ActionController::Parameters.


I was going to submit a PR, but I noticed that the gem spec only requires Rails 3.2, so I wasn't sure what the best approach might be for testing with a class that didn't appear until Rails 4.

@BookOfGreg
Copy link
Member

@jcarlson I would still welcome a PR, if it works on some versions of Rails then it's more progress than most make.

On earlier versions we tend to follow the if defined?(NewThingy) pattern.

I agree, this would be a convenient feature.

jcarlson added a commit to jcarlson/react-rails that referenced this issue Sep 6, 2018
Adds support for React.camelize_props to camelize an instance of
ActionController::Parameters hash, so that permitted, strong parameters
in a Rails controller can be passed to a React component.

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

No branches or pull requests

2 participants