ruby - how to use this class method within my Rails 3 code? -


i hoping resolved tonight great.

i added class method post.rb model

  def self.without_review     where(review: false)   end 

what trying show posts on site review=false. if review=true, want manually approve them before they're displayed. right now, posts getting displayed whether review true or false.

here's post controller

class postscontroller < applicationcontroller   before_filter :signed_in_user   before_filter :load_post, only: :destroy      def create     @post = current_user.posts.build(params[:post])     if @post.save       flash[:success] = "shared!"       redirect_to root_path     else       @feed_items = []       render 'static_pages/home'     end   end    def destroy     @post.destroy     redirect_to root_path   end    private      def correct_user       @post = current_user.posts.find_by_id(params[:id])       redirect_to root_path if @post.nil?     end      def load_post       @post = current_user.admin? ? post.find(params[:id]) : current_user.posts.find(params[:id])     end  end 

and here's full post.rb model

class post < activerecord::base   attr_accessible :content, :review   belongs_to :user   validates :user_id, presence: true   validates :content, presence: true    default_scope order: 'posts.created_at desc'        def self.without_review     where(review: false)   end   end 

the schema of posts table show how "review" set (last row)

create_table "posts", :force => true |t|     t.text     "content"     t.integer  "user_id"     t.datetime "created_at",                         :null => false     t.datetime "updated_at",                         :null => false     t.boolean  "review",          :default => false 

the static pages controller

class staticpagescontroller < applicationcontroller   def home     if signed_in?       @post = current_user.posts.build       @feed_items = current_user.feed.paginate(page: params[:page])     end   end     def post1     if signed_in?       @post = current_user.posts.build     end   end   end 

userscontroller (def show)

def show @user = user.find(params[:id]) @posts = @user.posts.paginate page: params[:page], :per_page => 15 end 

you didn't show controller/action actual listing of posts generated, guess have replace post.all post.without_review there.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -