I have an app that I've been developing that has so far only been a single user environment. I finally got to the point where I needed to add multi-user capabilities so I followed the railscast on authlogic to get a simple login.
I then added a has_many :items
and accepts_nested_attributes_for :items
and a belongs_to :user
to the correct models. I then dropped the database and setup and then migrated it. I also added a user_id
column to all my nested models.
After that, when I click on the "Create new item" link, I go to the new page and create a new item. When I go back to the item_index page, it's not showing up anymore. I can go to localhost/item/1 and see the record, so I know that it's being created, but when I try to view it in my item_index.html.erb it doesn't show up anymore.
Here's the basic loop that was working before I added the user. (It's rendering into a table)
<% for item in @items %>
<%= link_to item.name, item %>
<% end %>
I imagine that the loop is what's wrong, but I'm not entirely sure.
Thanks
edit: Here's what's happening in my index method in my item controller:
def index
@items = Item.search params[:search]
if @items.nil?
@items = Item.all
end
end
I have the weird if nil?
thing because I'm using thinking-sphinx and it was failing sometimes if the index was empty.
edit2:
If I change the index to have just
def index
@items = Item.all
end
Everything shows up. So that means that it has to do with thinking sphinx messing with my render
edit3: in thinking-sphinx fashion, I did some things unrelated to it, and it magically works again.