Hi Fred,
I am using rails-api because I am doing all interactions with the rails app in json. Using rails-api eliminates all of the rendering code and keeps heroku happy from a memory usage point of view.
From one of the many posts I found discussing this problem (this one from StackOverflow):
The error above comes from the
require()method inActiveSupport::Dependencies::Loadablebeing executed when callingparams.require(:user)...
strong_parametersinjectsActionController::StrongParametersintoActionController::Baseat the bottom of this file withActionController::Base.send :include, ActionController::StrongParametersThe
rails-apigem requires your app'sApplicationControllerextendActionController::APIin favor ofActionController::BaseThe application controllers don't know anything about
ActionController::StrongParametersbecause they're not extending the classActionController::StrongParameterswas included within. This is why therequire()method call is not calling the implementation inActionController::StrongParameters.To tell
ActionController::APIaboutActionController::StrongParametersis as simple as adding the following to a file inconfig/initializers.ActionController::API.send :include, ActionController::StrongParameters
This is one of the many "solutions" I tried that doesn't work for me. :'(
Thanks,
Don
On 07/25/2015 05:16 AM, Frederick Cheung wrote:
--
On Saturday, July 25, 2015 at 4:34:48 AM UTC+1, donz wrote:Unfortunately, no. That is exactly the problem. The expression
params.require(:user) (for example) returns a string in rails-api and an
object which has .permit as a method in just plain rails. All of the
"solutions" try to change the controller from one derived from ::Api
(does not support strong parameters) to one derived from ::Base (which
does support strong parameters). :'( .
Do you know why the payload is a string rather than a hash ?What format is the data being posted in (form data,json, xml etc ?) It seems to me that your first problem is to solve this - even if you were to solve the strong parameters bit presumably your code is expecting params[:user] to be a hash
Fred
On 07/24/2015 10:09 PM, BuyzLots wrote:
> Your payload looks like a string, is permit something you can call on a string object?
>
>
>
>> On Jul 24, 2015, at 9:31 PM, Donald Ziesig <donald@ziesig.org> wrote:
>>
>> Hi All!
>>
>> I have been trying just about everything I can find on the web to make rails-api work with strong_parameters but no matter what I do, I get the following error:
>>
>> NoMethodError (undefined method `permit' for "{email: xxx@xxx.org, password: xxxxxxxxx}":String):
>>
>> All of the answers I have found give ways to add StrongParameters to ApplicationController::Api, but none of them change the resulting error. Debug printouts show that the recommended changes are being executed. I generated a test app using rails without -api and it works fine, but is much bigger due to all of the non-api cruft.
>>
>> I am using both rails 4.0.2 and 4.0.9 (can't use higher versions due to some old but necessary gems).
>>
>> Any help would be appreciated.
>>
>> Thanks,
>>
>> Don Ziesig
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
>> To post to this group, send email to rubyonrails-talk@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/55B2E6FF.9060607%40ziesig.org.
>> For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5b254d75-5201-4d31-bec5-3c06a6a5edbf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/55B39BB7.6070407%40ziesig.org.--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuoEr2gL7GDKmEKvxjz-u_yMNdoHMcm7WCudD%2BjXTvaQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment