0

I have a model in which I have a boolean attribute, published. In my Post controller I have added it to my permitted attributes. Like this:

params.require(:post).permit([...], :published)

My index action that should list all published posts looks like this:

def index
    if session[:user_id]
      @posts = Post.paginate(:page => params[:page])
    else
      @posts = Post.where("published = 1").paginate(:page => params[:page])
    end
end

And lastly my form looks like this:

= form_for @post, :html => { :multipart => true } do |f|
  [...]
  .field
    = f.label :published, "Publicera:"
    = f.check_box :published      
  .actions
    = f.submit

Currently no posts is listen on my index page, even if I either the new or updat view checks the checkbox. And I'm not sure how to fix it, any ideas?

4

1 回答 1

1

问题似乎出在我的 where 谓词上。这有效:

@posts = Post.where(:published => true).paginate(:page => params[:page])
于 2013-07-12T18:22:02.810 回答