diff --git a/app/controllers/channels_controller.rb b/app/controllers/channels_controller.rb index ae62a20..acabc8e 100644 --- a/app/controllers/channels_controller.rb +++ b/app/controllers/channels_controller.rb @@ -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 - diff --git a/app/models/channel.rb b/app/models/channel.rb index 5bdf0e0..1256d64 100644 --- a/app/models/channel.rb +++ b/app/models/channel.rb @@ -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") } diff --git a/app/views/channels/_edit.html.erb b/app/views/channels/_edit.html.erb index a2ffc79..0f9e40c 100644 --- a/app/views/channels/_edit.html.erb +++ b/app/views/channels/_edit.html.erb @@ -1,13 +1,6 @@
<%= 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 %> -

<%= error_messages_for 'channel', :header_message => t(:try_again), :message => t(:channel_error) %>