我正在使用Thinking Sphinx进行全文搜索,关注此视频.
我想做以下事情:
@articles = Article.search(params[:search], :conditions => "published_at IS NOT NULL", :order => :created_at)
Run Code Online (Sandbox Code Playgroud)
问题是这不起作用.似乎搜索方法只接受哈希条件.我已经尝试了几种方法,但我对如何将"published_at IS NOT NULL"表示为哈希表示无能为力......
我有以下rails迁移:
create_table :articles do |t|
t.integer :user_id, :allow_null => false
t.integer :genre_id, :allow_null => false
t.string :url, :limit => 255, :allow_null => false
t.string :title, :limit => 60, :allow_null => false
t.text :summary, :limit => 350, :allow_null => false
t.integer :votes_count, :default => 0
t.datetime :published_at, :default => nil
t.timestamps
end
Run Code Online (Sandbox Code Playgroud)
首先在模型中验证所有"NOT NULL"的字段,所以我想知道我是否需要在迁移中烦扰allow_null?我不确定"NOT NULL"给数据库带来了什么好处,如果有的话.
在返回旧的Rails项目后,我发现没有任何破坏/删除链接工作,并且在确认弹出窗口上单击取消仍然会提交链接.
我的代码示例是:
<%= link_to 'Delete', admin_user_path(@user), :confirm => 'Are you sure?', :method => :delete %>
Run Code Online (Sandbox Code Playgroud) 说我做以下事情:
我需要做到这一点,以便用户返回主页(/)而不是返回/ posts/1
所以我需要允许骨干哈希路由工作,但不能修改历史记录.我个人更喜欢保留历史,但这是项目的要求.