fix channel validation error

This commit is contained in:
Lee Lawlor 2015-02-12 14:00:15 -05:00
parent 286519d86b
commit e25885a96e
3 changed files with 3 additions and 17 deletions

View File

@ -178,10 +178,8 @@ class ChannelsController < ApplicationController
format.html do format.html do
if @mychannel if @mychannel
render "private_show" render "private_show"
session[:errors] = nil
else else
render "public_show" render "public_show"
session[:errors] = nil
end end
end end
format.json { render :json => @channel.as_json(options) } format.json { render :json => @channel.as_json(options) }
@ -201,18 +199,14 @@ class ChannelsController < ApplicationController
# make updating attributes easier for updates via api # make updating attributes easier for updates via api
params[:channel] = params if params[:channel].blank? params[:channel] = params if params[:channel].blank?
if params["channel"]["video_type"].blank? && !params["channel"]["video_id"].blank? if @channel.valid?
@channel.errors.add(:base, t(:channel_video_type_blank))
end
if @channel.errors.count <= 0
@channel.save_tags(params[:tags][:name]) if params[:tags].present? @channel.save_tags(params[:tags][:name]) if params[:tags].present?
@channel.assign_attributes(channel_params) @channel.assign_attributes(channel_params)
@channel.set_windows @channel.set_windows
@channel.save @channel.save
@channel.set_ranking @channel.set_ranking
else else
session[:errors] = @channel.errors flash[:alert] = @channel.errors.full_messages.join(', ')
redirect_to channel_path(@channel.id, :anchor => "channelsettings") and return redirect_to channel_path(@channel.id, :anchor => "channelsettings") and return
end end
@ -606,4 +600,3 @@ class ChannelsController < ApplicationController
end end
end end

View File

@ -76,7 +76,7 @@ class Channel < ActiveRecord::Base
before_destroy :delete_feeds before_destroy :delete_feeds
validates :video_type, :presence => true, :if => lambda{ |channel| channel.video_id.present? } validates :video_type, :presence => { :message => I18n.t(:channel_video_type_blank) }, :if => lambda{ |channel| channel.video_id.present? }
scope :public_viewable, lambda { where("public_flag = true AND social != true") } scope :public_viewable, lambda { where("public_flag = true AND social != true") }
scope :not_social, lambda { where("social != true") } scope :not_social, lambda { where("social != true") }

View File

@ -1,13 +1,6 @@
<div class="FL"> <div class="FL">
<%= form_for @channel, :html => {:method => 'put'} do |c| %> <%= form_for @channel, :html => {:method => 'put'} do |c| %>
<% unless session[:errors].nil?
session[:errors].each do |attr, msg|
@channel.errors.add(attr, msg)
end
session[:errors] = nil %>
<% end %>
<p> <p>
<%= error_messages_for 'channel', :header_message => t(:try_again), :message => t(:channel_error) %> <%= error_messages_for 'channel', :header_message => t(:try_again), :message => t(:channel_error) %>
</p> </p>