ruby - How to setup controller to respond to a specific object rails -
i trying set controller responds "first" video record in database skip validations in model.
video.rb validates :link, presence: true, format: yt_link_format, unless: :skip_video_validation before_create :uid_link_match, unless: :skip_video_validation before_update :uid_link_match, unless: :skip_video_validation attr_accessor :skip_video_validation end
how set in controller can first video skip these validations.
def update @video = video.find(params[:id]) if @video == @video[0] @video.skip_video_validation = true if @video.update_attributes(video_params) flash[:success] = 'video updated!' redirect_to root_url else render 'edit' end else ... end
could please explain doing wrong , why.
full code should in controller
def update @user = user.find(params[:user_id]) @video = video.find(params[:id]) if @video == @user.videos[0] @video.skip_video_validation = true if @video.update_attributes(video_params) flash[:success] = 'video updated!' redirect_to root_url else render 'edit' end else ...
end
Comments
Post a Comment