We are making a Login system where you must activate your account with an activation code. Every user has a unique code. We can't figure out how to make a form that checks that the input of that form is equal to the unique activation code.
The form:
<%= form_for :user, :controller => :users, :action => 'check_authentication_token' do |f| %>
<%= f.text_field :authentication_token, :value => '' %>
<%= f.submit 'Activeren' %>
<% end %>
The controller action
def check_authentication_token
user = User.find_by(authentication_token: params[:user][:authentication_token])
if user && user.authenticate(user_params[:authentication_token])
redirect_to @user
else
redirect_to competitions_path
end
end
User table
create_table "users", force: true do |t|
t.string "name"
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.string "password_digest"
t.string "remember_token"
t.boolean "activated", default: false
t.string "authentication_token"
end
Route file
Wisemonkeys::Application.routes.draw do
get "users/new"
resources :competitions
resources :users
get 'pictures/new'
get 'competitions/new'
resources :pictures do
member do
get 'upvote'
end
end
get '/mypictures' => 'pictures#mypictures'
get '/voteresults' => 'pictures#voteresults'
get '/activatie' => 'users#check_authentication_token'
root 'competitions#index'
resources :sessions, only: [:new, :create, :destroy]
match '/signup', to: 'users#new', via: 'get'
match '/signin', to: 'sessions#new', via: 'get'
match '/signout', to: 'sessions#destroy', via: 'delete'
@useris undefined. Either change that touseror changeuser = User.find_by ...to@user = User.find_by ...user_params[:authentication_token]andparams[:user][:authentication_token]. Please confirm