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

Passing data example does not work #97

Closed
abrambailey opened this issue Nov 15, 2019 · 6 comments
Closed

Passing data example does not work #97

abrambailey opened this issue Nov 15, 2019 · 6 comments

Comments

@abrambailey
Copy link

From your readme:

<%= render_async users_path,
                 method: 'POST',
                 data: { fresh: 'AF' },
                 headers: { 'Content-Type': 'text' } %>

When I tried this, I get:

=> <ActionController::Parameters {"{:fresh"=>">"AF"}", "controller"=>"pages", "action"=>"sidebar_ads"} permitted: false>

@nikolalsvk
Copy link
Owner

Hey @abrambailey, thanks for creating an issue.

It looks like you maybe need to permit fresh as a parameter for your controller action. Are you doing that?

I'm guessing it would be something like this:

def user_params
  params.require(:user).permit(:fresh, ...)
end

@abrambailey
Copy link
Author

I was not doing this. Actually, I ended up just passing the data through the path like users_path(fresh: 'AF') in the end. Not sure why I didn't do that to begin with 😆

@nikolalsvk
Copy link
Owner

Ah OK 😄 Did you still need to permit the attribute you were passing in? (I'm trying to check whether there's actually a bug in the gem with the example you provided in the first comment)

@abrambailey
Copy link
Author

No, I didn't ... it worked perfectly without needing to permit using my method.

@nikolalsvk
Copy link
Owner

If you're trying to update the user, you probably need to make it like this

<%= render_async users_path,
                 method: 'POST',
                 data: { user: { fresh: 'AF' } },
                 headers: { 'Content-Type': 'text' } %>

@nicholaswellens
Copy link

I had the same problem, where the params started with eg. "{:fresh"=>">"AF"}". Worked around it by sending in JSON format:

eg.

<%= render_async users_path,
                 method: 'POST',
                 data: { fresh: 'AF' }.to_json,
                 headers: { 'Content-Type': 'application/json' } %>

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

No branches or pull requests

3 participants