POST only permited parameters to Rails from railsResource in angularJS
This will help to POST only permitted attributes to your Rails app when executing 'update' on railsResource
object.
Define transformer:
@app.factory('railsStrongParameters', ->
(data, resource) ->
if resource.permit
for key of data
unless angular.isFunction(data[key])
unless key in resource.permit
delete data[key]
data
)
Then add it to your model transformers list:
@app.factory('Article', ['railsResourceFactory', (railsResourceFactory) ->
Article = railsResourceFactory
url: '/articles'
name: 'article'
requestTransformers: [
'railsFieldRenamingTransformer',
'railsStrongParameters',
'railsRootWrappingTransformer'
]
Article.permit = ['title', 'body']
Article
])
Now you can just copy permitted attributes straight from Rails.
Written by Gatis Tomsons
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#