curl - Issue with PUT in Rails -
i'm working on creating survey application create survey on rails server , long user hasn't taken survey next time open android app they'll displayed survey take. once user takes survey i'd update survey contain user no longer sent same survey each time log in. i'm using habtm relationship between users/surveys.
i'm able survey/let user take it/create user choices on server i'm struggling updating survey user took survey. i'm pretty sure problem put request (the auth_token used identify user).
started put "/api/v1/surveys/4?auth_token=8d707d9fa2b279f381eb416f1be887c0" here's controller:
module api module v1 class surveyscontroller < applicationcontroller # before_action :restrict_access respond_to :json def survey @survey = survey.check_survey params[:auth_token] redirect_to api_v1_survey_path(@survey) end def update @survey = survey.find(params[:id]) @user = user.find_user_by_token params[:auth_token] complete_survey @survey, @user end my model:
class survey < activerecord::base has_many :surveytizations has_many :questions, :through => :surveytizations has_and_belongs_to_many :users, -> { uniq } def complete_survey (survey, user) survey.users << user survey.number_taken += 1 if survey.number_taken == survey.survey_limit survey.survey_finished = true end end in using curl test rails routes goes how update attribute of user. i'm pretty new curl - if wanted test updating array of users additional user, how that? tried survey[users]=user1 doesn't seem work.
thanks in advance help!
Comments
Post a Comment