mardi 6 octobre 2015

Rails validate user entry

I am working on a project and relatively very new to Rails. What I wanted to do is redirect the user to the username and email entry form. Here is my controller:

class UsersController < ApplicationController def create @user = User.create!(user_params) flash[:notice] = "#{@user.user_id} was successfully created." redirect_to movies_path end

Here's my model:

class User < ActiveRecord::Base validates :user_id, uniqueness: true end

What I wanted to do is just send the user back to the new user view by using flash if user_id already exists.

Thank you for the help.

Aucun commentaire:

Enregistrer un commentaire