ruby on rails - What action should I use for create_or_update operation -



ruby on rails - What action should I use for create_or_update operation -

rails has basic rest operation create/update/show/destroy, if want action create or update existing record should create custom action ?

i know rails has first_or_initialize, doesn't seem fit definition of create or update.

in understanding create should create new record , not update existing 1 , update should update without create new one.

here example:

i have model blog, tag, , bring together table blog_tags reference blog_id, tag_id, , user_id record suggest tag blog post.

[blog]>-[blog_tag]-<[tag] | [user]

my thought

i'm thinking of new action put create_or_update illustration , route , have routes blog/[blog_id]/tag/[tag_id_to_add]/create_or_update. don't know right way or not.

putting in create or update makes no difference. take update since method calling update. create sure it's documented action can create , update model.

def update user = user.find_or_initialize_by(email: user_params[:email]) user.update_attributes(user_params) end

as verb, update action defined resource should have post/put verbs default.

ruby-on-rails rest crud

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -