ruby script/plugin install svn://svn.railsfreaks.com/projects/acts_as_solr/trunk
rake aborted!
Bad file descriptor - connect(2)
(See full trace by running task with --trace)
depot\vendor\plugins\acts_as_solr\solr directory\
java -jar start.jar
desc 'Starts Solr. on windows . Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.'
task :start_win do
begin
n = Net::HTTP.new('localhost', SOLR_PORT)
n.request_head('/').value
rescue Net::HTTPServerException #responding
puts "Port #{SOLR_PORT} in use" and return
rescue Errno::EBADF #not responding
Dir.chdir(SOLR_PATH) do
exec "java -Dsolr.data.dir=solr/data/#{ENV['RAILS_ENV']} -Djetty.port=#{SOLR_PORT} -jar start.jar"
sleep(5)
puts "#{ENV['RAILS_ENV']} Solr started sucessfuly on #{SOLR_PORT}, pid: #{pid}."
end
end
end
rake solr:start_win
class Job < ActiveRecord::Base
acts_as_solr :include => [:category], :fields=>[:name,:description,:resolution]
belongs_to :category
belongs_to :user
end
class Category < ActiveRecord::Base
has_many :jobs
acts_as_solr :include => [:jobs]
end
ruby script/console
Job.rebuild_solr_index
Category.rebuild_solr_index
@results = Job.find_by_solr("code monkey")
module ActsAsSolr
module PaginationExtension
def paginate_search(query, options = {})
options, page, per_page = wp_parse_options!(options)
pager = WillPaginate::Collection.new(page, per_page, nil)
options.merge!(:offset => pager.offset, :limit => per_page)
result = result = find_by_solr(query, options)
returning WillPaginate::Collection.new(page, per_page, result.total_hits) do |pager|
pager.replace result.docs
end
end
end
end
module ActsAsSolr::ClassMethods
include ActsAsSolr::PaginationExtension
end
def search
begin
@jobs =Job.paginate_search params[:query_string], :page => params[:page], :per_page => 10
@query_string=params[:query_string]
rescue
#handle any errors here
#flash[:notice] = 'There was a problem with your query'
@jobs = Job.paginate :page => params[:page]
end
end
<% form_tag :action => 'search' do %>
<%= text_field_tag :query_string , @query_string %>
<%= submit_tag "Search" %>
<% end %>
<p><b><%= pluralize @jobs.total_entries, 'job' %></b> found.</p>
<table>
<%= render :partial => 'job', :collection => @jobs %>
</table>
<%= will_paginate @jobs, :params =>{:query_string=> @query_string} -%>
will_paginate @jobs, :params =>{:query_string=> @query_string}
def search
begin
@jobs =Job.paginate_search params[:query_string], :page => params[:page], :per_page => 3
@query_string=params[:query_string]
rescue
#handle any errors here
#flash[:notice] = 'There was a problem with your query'
@jobs = Job.paginate :page => params[:page]
end
respond_to do |format|
format.html do
#If the request is a live search just return the rendered search results
#rather than the whole page
render :action => 'live_search.html.erb', :layout =>false if request.xml_http_request?
end
end
end
<%= observe_field(:query_string, :url =>{ :controller => :jobs, :action => :search }, :frequency => 0.5, :update => :search_results, :with => "'query_string=' + escape(value)") %>
<% unless logged_in? %>
<%= error_messages_for :user %>
<div id="login_div">
<h1>Login or sign up</h1>
<%= error_div_for user %>
<% remote_form_for :user, :url => {:controller => :account, :action => :signup}, :update => { :success => "login_div", :failure => "login_div" } do |f| -%>
<p><label for="email">Email</label><br/>
<%= f.text_field :email %></p>
<p><label for="password">Password</label><br/>
<%= f.password_field :password %></p>
<p><label for="password_confirmation">Confirm Password</label><br/>
<%= f.password_field :password_confirmation %></p>
<p><%= submit_tag 'Sign up' %></p>
<% end -%>
</div>
<%= observe_field(:user_password, :url =>{ :controller => :account, :action => :autofill }, :frequency => 0.5, :with => "'email='+ escape($('user_email').value) + '&password=' + escape($('user_password').value)") %>
<% end %>
<%= observe_field(:user_password, :url =>{ :controller => :account, :action => :autofill }, :frequency => 0.5, :with => "'email='+ escape($('user_email').value) + '&password=' + escape($('user_password').value)") %>
<% remote_form_for :user, :url => {:controller => :account, :action => :signup}, :update => { :success => "login_div", :failure => "login_div" } do |f| -%>
:update => { :success => "login_div", :failure => "login_div" }
def signup
@user = User.new(params[:user])
return unless request.post?
@user.save!
self.current_user = @user
if request.xml_http_request?
render :action => 'welcome.html.erb', :layout =>false
end
redirect_back_or_default(:controller => '/account', :action => 'index')
flash[:notice] = "Thanks for signing up!"
rescue ActiveRecord::RecordInvalid
if request.xml_http_request?
render :action => 'signup', :layout =>false
end
end
request.xml_http_request?method which tells you if the call was a ajax request.
before_filter :adjust_format_for_ajax
def adjust_format_for_ajax
request.format = :ajax if request.xml_http_request?
end
respond_to do |format|
format.html do
flash[:notice] = "Thanks for signing up!"
redirect_back_or_default(:controller => 'account', :action => 'index')
end
format.ajax do
render :template=>'shared/welcome.html.erb', :layout =>false
return
end
end
<code language=ruby>
some ruby code
</code>
require 'syntax/convertors/html'
require 'win32/clipboard'
include Win32
namespace :format do
desc "This task will format code in the clipboard or file specified by file=\"filename\" as html"
task :ruby4display do
BloggingTools.ruby4display
end
desc "This task will format code in the clipboard or file specified by file=\"filename\" as html"
task :html4display do
BloggingTools.html4display
end
end
#Actual functions are defined in a separate class to ease testing and keep things clean and dry
class BloggingTools
def self.ruby4display
convertor = Syntax::Convertors::HTML.for_syntax "ruby"
code_html = convertor.convert(input)
output code_html
end
def self.html4display
convertor = Syntax::Convertors::HTML.for_syntax "xml"
code_html = convertor.convert(input)
output code_html
end
def self.input
if ENV['file']
puts "#{ENV['file']} will be processed and copied to the clipboard"
in_data = File.read(ENV['file'])
else
puts "no arguments supplied data will be taken from clipboard"
in_data = Clipboard.data
end
end
def self.output code_html
if ENV['file']
fn= "#{File.basename(ENV['file'], File.extname(ENV['file']))}.html"
puts "output to file #{fn}"
in_data = File.open(fn, File::WRONLY|File::TRUNC|File::CREAT)
in_data.puts code_html
else
puts "output to clipboard"
Clipboard.set_data(code_html)
end
end
end
July 2007 August 2007 September 2007 December 2007 January 2008 February 2008 March 2008 April 2008 June 2008 July 2008 August 2008 October 2008 November 2008 January 2009
Subscribe to Comments [Atom]