vendredi 28 juillet 2017

Create default value for param when not sent from Client Side in Rails

I have an application whose server-side is on Rails and the client-side is on React.

I have a situation where I allow a user to create bullet points for a TV show which they create.

These bullet points are sent as params to the Rails side but the issue is if there was a point when there is only one bullet point and then we try to delete it then it doesn't include the bullet_point state in the request.

I added this code to check if bullet point parameter exists, since the only situation it won't exist is when there are no bullet points.

if !prms.has_key?(:bullet_points)

which gives the correct boolean response.

Is there a way to reset bullet points to default in this situation?

bullet_points is an attribute of type text which has been serialized as an Array in the TVShow model

Aucun commentaire:

Enregistrer un commentaire