fix channel validation error
This commit is contained in:
		@@ -178,10 +178,8 @@ class ChannelsController < ApplicationController
 | 
			
		||||
      format.html do
 | 
			
		||||
        if @mychannel
 | 
			
		||||
          render "private_show"
 | 
			
		||||
          session[:errors] = nil
 | 
			
		||||
        else
 | 
			
		||||
          render "public_show"
 | 
			
		||||
          session[:errors] = nil
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
      format.json { render :json => @channel.as_json(options) }
 | 
			
		||||
@@ -201,18 +199,14 @@ class ChannelsController < ApplicationController
 | 
			
		||||
    # make updating attributes easier for updates via api
 | 
			
		||||
    params[:channel] = params if params[:channel].blank?
 | 
			
		||||
 | 
			
		||||
    if params["channel"]["video_type"].blank? && !params["channel"]["video_id"].blank?
 | 
			
		||||
      @channel.errors.add(:base, t(:channel_video_type_blank))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    if @channel.errors.count <= 0
 | 
			
		||||
    if @channel.valid?
 | 
			
		||||
      @channel.save_tags(params[:tags][:name]) if params[:tags].present?
 | 
			
		||||
      @channel.assign_attributes(channel_params)
 | 
			
		||||
      @channel.set_windows
 | 
			
		||||
      @channel.save
 | 
			
		||||
      @channel.set_ranking
 | 
			
		||||
    else
 | 
			
		||||
      session[:errors] = @channel.errors
 | 
			
		||||
      flash[:alert] = @channel.errors.full_messages.join(', ')
 | 
			
		||||
      redirect_to channel_path(@channel.id, :anchor => "channelsettings") and return
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@@ -606,4 +600,3 @@ class ChannelsController < ApplicationController
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -76,7 +76,7 @@ class Channel < ActiveRecord::Base
 | 
			
		||||
 | 
			
		||||
  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 :not_social, lambda { where("social != true") }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,6 @@
 | 
			
		||||
<div class="FL">
 | 
			
		||||
 | 
			
		||||
  <%= 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>
 | 
			
		||||
      <%= error_messages_for 'channel', :header_message => t(:try_again), :message => t(:channel_error) %>
 | 
			
		||||
    </p>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user