if @article.save flash[:notice] = "Article was created." redirect_to articles_path else flash[:notice] = "The article could not be saved!" render :new end end
Article.new(params[:article]) if @article.save flash[:notice] = "Article was created." redirect_to articles_path else flash[:notice] = "The article could not be saved!" render :new end end
failed to save." created: "Article created successfully." new: "New Article" update: "Save Changes" create: "Save Article" comment: created: "Comment posted, you're internet famous." spam: "Burn your own face off, spammer." create: "Post Comment" status: moderation: "Comment is pending moderation." approved: "Comment approved." A YAML Dictionary
Article.new(params[:article]) if @article.save flash[:notice] = "Article was created." redirect_to articles_path else flash[:notice] = "The article could not be saved!" render :new end end
validates_length_of :body, :min => 100 :message => " must be at least 100 characters bro." def self.recent order('created_at DESC').limit(10) end def attribution "written by #{author.full_name}" end end
:title, :message => "The article needs a title." def self.recent order('created_at DESC').limit(10) end def attribution "written by #{author.full_name}" end end
if respond_to?(:params) && params[:locale] LocaleSetter::Param.for(params[:locale]) end end end module LocaleSetter module Param def self.for(param) LocaleSetter::Matcher.match([param]) end end end
against = available) matched = (sanitize(requested) & against).first matched.to_sym if matched end def self.available I18n.available_locales.map(&:to_s) end # sanitize methods are just for case & whitespace # ... end end
if user && user.respond_to?(:locale) && user.locale && !user.locale.empty? LocaleSetter::Matcher.match(user.locale) end end end end module LocaleSetter # ... def from_user if respond_to?(:current_user) && current_user LocaleSetter::User.for(current_user) end end end
if controller.respond_to?(:before_filter) controller.before_filter :set_locale end end def set_locale i18n.locale = from_params || from_user || from_http || i18n.default_locale end def from_user if respond_to?(:current_user) && current_user LocaleSetter::User.for(current_user) end end
target = "#{method}_#{I18n.locale}" respond_to?(target) ? send(target) : attribute(method) end end end end class Article < ActiveRecord::Base translates :title, :body end