Can't figure out why my form won't update

Viewed 92

In my application a user is created using a telegram bot sending messages to my Rails api.

Once a user is created, it can add instagram accounts associated with it. When a user adds a new instagram account has_secure_token generates a random token and sends the user this expirable link: www.example.com/set/:token.

Routes:

resources :instagram_users, except: [:new, :create, :edit]
get 'set/:token', to: 'instagram_users#edit', as:  'set'

Controller:

def edit
  @instagram_user = InstagramUser.find_by(password_reset_token: params[:token])
end

def update
  @instagram_user = InstagramUser.find(params[:id])
  correct_user(@instagram_user, params[:token])
  if @instagram_user.update_attributes(instagram_user_params)
    flash[:success] = "Instagram user success!"
    redirect_to dashboard_path
  else
    flash[:alert] = "Something went wrong!"
    render 'edit'
  end
end

private

def instagram_user_params
  params.require(:instagram_user).permit(:password, :password_confirmation, :backup_code, :token)
end

def correct_user(ig_user, token)
  redirect_to root_url unless ig_user.password_reset_token == token
end

My view:

edit.html.haml ('set/:token')
= form_for @instagram_user, url: instagram_user_path(@instagram_user.id), html: { class: 'form-horizontal' } do |f|
      = render 'shared/error_messages'

      = f.label :password
      = f.password_field :password, class: 'form-control'
      = f.label :password_confirmation, "Confirmation"
      = f.password_field :password_confirmation, class: 'form-control'
      = f.label :backup_code
      = f.text_field :backup_code, class: 'form-control'

      = hidden_field_tag :token, @instagram_user.password_reset_token
      = f.submit "Save Changes", class: "btn btn-primary"

Now I have tried several different ways with form_for, but it is just not hitting the update action.

Edit:

rails routes:

           root GET    /                              pages#home
instagram_users GET    /instagram_users(.:format)     instagram_users#index
instagram_user  PATCH   /instagram_users/:id(.:format) instagram_users#update
                PUT    /instagram_users/:id(.:format)  instagram_users#update
                DELETE /instagram_users/:id(.:format)  instagram_users#destroy
set             GET    /set/:token(.:format)           instagram_users#edit

                GET    /:token/dashboard(.:format)     instagram_users#show

When submitting the form:

Started GET "/set/y2mSCzfbHZ1HgUxtbQnaMZsR?utf8=%E2%9C%93&_method=patch&authenticity_token=E4mLcqieWsibgCt1VWM%2FKDv1YS%2FWtpS8%2BYk82%2BmqP08

phCpvq62lebpUGTfHFSKD%2BDtO%2FtxX%2FKUHr4mP3iXYcw%3D%3D&instagram_user%5Bpassword%5D=[FILTERED]&instagram_user%5Bpassword_confirmation%5D=[FIL
TERED]&instagram_user%5Bbackup_code%5D=1234&token=y2mSCzfbHZ1HgUxtbQnaMZsR&commit=Save+Changes" for ::1 at 2017-11-18 09:00:31 -0600
Processing by InstagramUsersController#edit as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"E4mLcqieWsibgCt1VWM/KDv1YS/WtpS8+Yk82+mqP08phCpvq62lebpUGTfHFSKD+DtO/txX/KUHr4mP3iXYcw==",
"instagram_user"=>{"password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "backup_code"=>"1234"}, "token"=>"y2mSCzfbHZ1HgUxtbQnaMZsR
", "commit"=>"Save Changes"}
  InstagramUser Load (31.2ms)  SELECT  "instagram_users".* FROM "instagram_users" WHERE "instagram_users"."password_reset_token" = $1 LIMIT $2
  [["password_reset_token", "y2mSCzfbHZ1HgUxtbQnaMZsR"], ["LIMIT", 1]]
  Rendering instagram_users/edit.html.haml within layouts/application
  Instagram Load (0.6ms)  SELECT  "instagrams".* FROM "instagrams" WHERE "instagrams"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  Rendered shared/_error_messages.html.haml (9.9ms)
  Rendered instagram_users/edit.html.haml within layouts/application (72.6ms)
Completed 200 OK in 263ms (Views: 203.4ms | ActiveRecord: 31.8ms)
0 Answers
Related