I have one model but two different forms ,one form i am saving through create action and another one through student_create action.I want to validate a field in student_create action form and leave other one free.How do i do it?Any help will be appreciated
class BookController < ApplicationController
def create
if @book.save
redirect_to @book #eliminated some of the code for simplicity
end
end
def student_create
if @book.save #eliminated some of the code for simplicity
redirect_to @book
end
end
I have tried this but it didnt work
class Book < ActiveRecord::Base
validates_presence_of :town ,:if=>:student?
def student?
:action=="student_create"
end
end
Also this didnt work
class Book < ActiveRecord::Base
validates_presence_of :town ,:on=>:student_create
end
I was able to acomplish it what i wanted to do by giving it an option
:allow_nil=>true