I want to know if you guys tested this sphinx in multiple application instance, single database, with multiple sphinx? What's the best thing to do? I'm having problem with regards to the indexing and starting of sphinx.
Instead of the somewhat clunky before_filter params[:product][:category_ids] ||= [] one can get away with a hidden field named product[category_ids][] that has an empty value plus then rejecting blank? category_ids in the model in #attributes=
custom tags can be built with Prawn::Format. EPS support is a 'would-be-nice' feature, but I haven't had a need for it just yet. You can background a JPG or PNG in Prawn, but it does have that resolution issue.
The page based filters will be in Prawn 0.5, porting the repeating page elements interface from PDF::Wrapper.
So if you like those features, keep an eye on Prawn for changes between now and 1.0. While I can't promise we'll hit them all, at least some will be addressed.
I need to store settings by environment but started off simply with my config file at: \config\config.yml. The only setting I had was this:
attachment_volume: \\attach\transfers
With this, cod I'm able to load the file within my initializer and reference it just fine from calling code within an ActiveRecord model class. So far so good.
Since this setting is a server location that varies by environment, I tried to use the by-environment structure and changed my config file to this:
development:
attachment_volume: \\attach\transfers
test:
attachment_volume: \\attach\test\transfers
I get the following error during that indicates it didn't like the second instance of the colon on the second line. Here is the real error: Uncaught exception: syntax error on line 1, col 20: ` attachment_volume: \\atlas\transfer\greenlight\predevelopment\attachments'
I've followed the RailsCast and have settings that look like this:
development:
images_path: \\sysimages\2009\
when the initializer runs, it fails with an error that suggest that it doesn't allow for the backward slashes. How do store a string that is a path in a YAML file that Ruby can load? Thanks in advance
I got a question, I've already written my .rsel file and I would like to pass it a parameter to specify wich product to test. Does someone have an idea?
Basically I like: work with tags, put a eps in background and write data over the image because eps keep the resolution and filters(before_page_create, even_pages and something like that)
Yeah, I'd like to echo what Ozgur said. Without much analysis it seems to me that depending on object id's filling up the space from 1 up seems like a needless dependency on Rails implementation choices. AR#find already has support for :offset and :limit. Those seem preferable. Here's a class I find useful:
class Incrementally
# Don't process every object in the database -- do it a few at a time
def self.process( an_active_record_class, at_a_time = 1000)
objects_count = an_active_record_class.count
i = 0
raise "at_a_time must be greater than 0" if at_a_time < 1
until( i > objects_count)
objects = an_active_record_class.find( :all, :offset => i, :limit => at_a_time)
objects.each do |instance|
if block_given?
yield instance
end
end
i += at_a_time
end
end
end # class
It could be made a lot nicer of course but you get the idea.
When ever I create a new invoice I'd like to send an e-mail to the client with that invoice attached as a PDF. I know how to send an e-mail and I now how to generate a PDF. But I don't know how to magically attache that very same PDF to the e-mail. I have to attache the PDF because the rails app is not reachable from the internet. Any ideas on this?
Ryan, i followed ur screen cast tens of times but dont get it working. The problem is that resulting SQL, mixes up the corresponding values. Do you know what might be wrong? (Rails 2.2.2)
Example SQL i get to logs: SELECT * FROM `properties` WHERE (properties.price_unit = 'buy' AND properties.offer = 'USD' AND properties.area_unit = 'once' AND properties.kind = 'meter' AND properties.period = 'apartment')
So, those values are mixed up and in wrong order. Please, could u tell how I can find the problem.
I haven't even watched it yet, but I know I'm gonna love this one. I've had my eye on Prawn for an upcoming project, and I'm hoping it'll best the previous pdf-writer library.
This is for Rails 2.3.2 correct? I've got it running here and can't get the batch methods to work, instead I'm getting an undefined method exception when calling ModelName#each.
Ryan, this is awesome. Can you also over SSL Certificates and how to integrate them with your application when processing credit cards? that would be awesome.
Thanks for the episode!
I was curious how to output unicode characters into the pdf, until found it to be really easy - what matters is only the font file, which can be put somewhere under rails root and pointed by pdf.font method.
http://pastie.org/419177
Great podcast (as usual)... I got to say that although I love the fact that it is easier to generate PDF files I'm kinda torn by the need to "code" the actual look and feel of that PDF file whereas with web application we get the benefit of the CSS and such.
Any idea on how we could use an approach similar to HTML+CSS when generating our PDF?
I creating a simple shopping cart, where you can add / remove itens, but since the field have the same name because :index => nil, the observe_field I have is not working.
Does anyone have some tip on using oberve_field here?
I noticed that this works only when application.html.erb layout is used. If using something other than that and in your controller saying layout 'some_layout' it will render js.erb in HTML.
Is this a bug or a feature? or am I doing something wrong?
I am using rails 2.2.2
Hi guys,
When I have the 2 models : product and category done and the table categories_products ready, how do I proceed with it?
if I have p = @product.first
and p.categories.size gives me the correct count BUT how do I make new relation between the existing category and product.
p.categories.new attempts to create the category?
Thanks
Hi,
very usefull tutorial. works *nearly* well in development and production.
I discovered one problem. My setup on the server (not local pc):
production: foo.com
development: foo.bar (my laptop is configured with /etc/hosts: 1.2.3.4 foo.bar.
works fine, but the caching of firefox or passenger (not sure which) leads to the result that a request to foo.bar delivers content from production database and visa versa. Depens which url I used before.
restarting apache and/or empty the firefox cache solves the problem. But it is still annoying.
You need to have "format.pdf" in your controller for the method you're doing this on. Like Ryan said earlier, you only need that if you already have a format block in your controller already.
Great screencast, Ryan! Very timely for me, as I was implementing this very thing in one of my apps last week. If Prawto's documentation had been _half_ as easy to understand as this, it would have saved me a lot of frustration. :)
I have a question. Is there a way (with Javascript maybe ?) to send to the printer the pdf, directly from the web page (and not generate the PDF and select "print" on the PDF reader) ?
What I want is more or less a button (or hyperlink) on a webpage called "print". It generates pdf but it is hided to the user.
@mephux, I should have clarified this in the screencast. If you already have a respond_to block in the controller, then you will need to add a format.pdf line. Otherwise Rails should automatically handle this.
I want to know if you guys tested this sphinx in multiple application instance, single database, with multiple sphinx? What's the best thing to do? I'm having problem with regards to the indexing and starting of sphinx.
Thanks
Instead of the somewhat clunky before_filter params[:product][:category_ids] ||= [] one can get away with a hidden field named product[category_ids][] that has an empty value plus then rejecting blank? category_ids in the model in #attributes=
@Thiago,
custom tags can be built with Prawn::Format. EPS support is a 'would-be-nice' feature, but I haven't had a need for it just yet. You can background a JPG or PNG in Prawn, but it does have that resolution issue.
The page based filters will be in Prawn 0.5, porting the repeating page elements interface from PDF::Wrapper.
So if you like those features, keep an eye on Prawn for changes between now and 1.0. While I can't promise we'll hit them all, at least some will be addressed.
I thought for sure a permalink set as "1-epson-abcd-1234" would fail, but sure enough, to_i still converts it to 1.
I must admit I'm not entirely certain why or how, but it does. I will have to look into this.
I need to store settings by environment but started off simply with my config file at: \config\config.yml. The only setting I had was this:
attachment_volume: \\attach\transfers
With this, cod I'm able to load the file within my initializer and reference it just fine from calling code within an ActiveRecord model class. So far so good.
Since this setting is a server location that varies by environment, I tried to use the by-environment structure and changed my config file to this:
development:
attachment_volume: \\attach\transfers
test:
attachment_volume: \\attach\test\transfers
I get the following error during that indicates it didn't like the second instance of the colon on the second line. Here is the real error: Uncaught exception: syntax error on line 1, col 20: ` attachment_volume: \\atlas\transfer\greenlight\predevelopment\attachments'
Here is full error stack:
Exiting C:/Ruby/lib/ruby/1.8/yaml.rb:133:in `load'
C:/Ruby/lib/ruby/1.8/yaml.rb:133:in `load'
C:/Ruby/lib/ruby/1.8/yaml.rb:144:in `load_file'
C:/Ruby/lib/ruby/1.8/yaml.rb:143:in `open'
C:/Ruby/lib/ruby/1.8/yaml.rb:143:in `load_file'
C:/TFS/GreenLight/DEV/server/config/initializers/load_config.rb:2
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in `load_without_new_constant_marking'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in `load'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in `load'
./script/../config/../vendor/rails/railties/lib/initializer.rb:550:in `load_application_initializers'
./script/../config/../vendor/rails/railties/lib/initializer.rb:549:in `each'
./script/../config/../vendor/rails/railties/lib/initializer.rb:549:i
n `load_application_initializers'
./script/../config/../vendor/rails/railties/lib/initializer.rb:167:in `process'
./script/../config/../vendor/rails/railties/lib/initializer.rb:112:in `send'
./script/../config/../vendor/rails/railties/lib/initializer.rb:112:in `run'
C:/TFS/GreenLight/DEV/server/config/environment.rb:16
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in `require'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in `require'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/../lib/mongrel/rails.rb:147:in `rails'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:113:in `cloaker_'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:149:in `call'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:149:in `listener'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:99:in `cloaker_'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:50:in `call'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:50:in `initialize'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:84:in `new'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:84:in `run'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/command.rb:212:in `run'
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:281
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in `load_without_new_constant_marking'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in `load'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in `load'
C:/TFS/GreenLight/DEV/server/vendor/rails/railties/lib/commands/servers/mongrel.rb:64
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in `require'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in `require'
C:/TFS/GreenLight/DEV/server/vendor/rails/railties/lib/commands/server.rb:49
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
./script/server:3
C:/Ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.4/lib/ruby-debug.rb:101:in `debug_load'
C:/Ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.4/lib/ruby-debug.rb:101:in `debug_program'
C:/Ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.4/bin/rdebug-ide:82
C:\Ruby\bin\rdebug-ide:19:in `load'
C:\Ruby\bin\rdebug-ide:19
-e:2:in `load'
-e:2
Uncaught exception: syntax error on line 1, col 20: ` attachment_volume: \\atlas\transfer\greenlight\predevelopment\attachments'
Has anyone been able to get the by environment structure load to work? Please advise? Thanks in advance.
I've followed the RailsCast and have settings that look like this:
development:
images_path: \\sysimages\2009\
when the initializer runs, it fails with an error that suggest that it doesn't allow for the backward slashes. How do store a string that is a path in a YAML file that Ruby can load? Thanks in advance
Yet another option in application controller:
exempt_from_layout /\.js\.erb$/
I am having the same issues with the js.erb template being rendered within an HTML layout.
The only 2 solutions I have found so far have been
doing:
format.js { render :layout => false }
every time in the controller OR doing this in the application controller:
layout proc { |controller| controller.request.xhr? ? nil : 'my_html_layout' }
I am hoping there is a better solution.
I got a question, I've already written my .rsel file and I would like to pass it a parameter to specify wich product to test. Does someone have an idea?
Thanks
@Gregory
Basically I like: work with tags, put a eps in background and write data over the image because eps keep the resolution and filters(before_page_create, even_pages and something like that)
off topic, but one of your ads says "Powered by Railsmachine". Isn't railscasts being run on slicehost?
Great screen cast, Ryan!
Came just in time when I needed it! :)
Ryan, you say to add
@user.admin = params[:user][:admin] if current_user.admin?
to prevent mass assignment of the admin field.
Where would this piece of code go exactly? In the update method of the controller?
Over there we already have
@user = User.find(params[:id])
..sry im new at this...
Yeah, I'd like to echo what Ozgur said. Without much analysis it seems to me that depending on object id's filling up the space from 1 up seems like a needless dependency on Rails implementation choices. AR#find already has support for :offset and :limit. Those seem preferable. Here's a class I find useful:
class Incrementally
# Don't process every object in the database -- do it a few at a time
def self.process( an_active_record_class, at_a_time = 1000)
objects_count = an_active_record_class.count
i = 0
raise "at_a_time must be greater than 0" if at_a_time < 1
until( i > objects_count)
objects = an_active_record_class.find( :all, :offset => i, :limit => at_a_time)
objects.each do |instance|
if block_given?
yield instance
end
end
i += at_a_time
end
end
end # class
It could be made a lot nicer of course but you get the idea.
When ever I create a new invoice I'd like to send an e-mail to the client with that invoice attached as a PDF. I know how to send an e-mail and I now how to generate a PDF. But I don't know how to magically attache that very same PDF to the e-mail. I have to attache the PDF because the rails app is not reachable from the internet. Any ideas on this?
Awesome. I tried to figure this out several months back and hit a brick wall. Thanks!
I have been trying to get the named scopes to work in my model without any success. How to do next?
excuse me, I don't know is this right place for my query.
I tried to install thinking-sphinx but i got empty folder
F:\RubyProjects\SphinxTest>ruby script/plugin install git://github.com/freelancing-god/thinking-sphinx.git
Then I download thinking-sphinx from http://github.com/freelancing-god/thinking-sphinx/tree/master
and install it as a gem , as following
C:\Think-Sphinx>gem build thinking-sphinx.gemspec
Successfully built RubyGem
Name: thinking-sphinx
Version: 1.1.6
File: thinking-sphinx-1.1.6.gem
C:\Think-Sphinx>gem install thinking-sphinx-1.1.6.gem
Successfully installed thinking-sphinx-1.1.6
1 gem installed
Installing ri documentation for thinking-sphinx-1.1.6...
Installing RDoc documentation for thinking-sphinx-1.1.6...
Now when I run rake task. I got following error.
F:\RubyProjects\SphinxTest>rake thinking-sphinx:index
(in F:/RubyProjects/SphinxTest)
rake aborted!
Don't know how to build task 'thinking-sphinx:index'
(See full trace by running task with --trace)
Why this is not working?
@Thiago:
What specifically is rghost nicer for? I asked for feedback on what we should steal from it a while ago :)
I've been took a look in prawn and rghost, I haven't choose one yet. I like prawn but rghost is easier but I need the ghostscript in the server.
@jhc_
Thank you! It works for me
Ryan, i followed ur screen cast tens of times but dont get it working. The problem is that resulting SQL, mixes up the corresponding values. Do you know what might be wrong? (Rails 2.2.2)
Example SQL i get to logs: SELECT * FROM `properties` WHERE (properties.price_unit = 'buy' AND properties.offer = 'USD' AND properties.area_unit = 'once' AND properties.kind = 'meter' AND properties.period = 'apartment')
So, those values are mixed up and in wrong order. Please, could u tell how I can find the problem.
Thanks!
I haven't even watched it yet, but I know I'm gonna love this one. I've had my eye on Prawn for an upcoming project, and I'm hoping it'll best the previous pdf-writer library.
Thanks again, Ryan!
@Alexander
About ./script/plugin not working :
http://rails.lighthouseapp.com/projects/8994/tickets/2018-ruby-19-compat-plugininstall-git-always-fails-in-ruby-19
Hey - quick question about the SSL cert
I noticed that in this tutorial, the SSL cert is only valid for 365 days.
What happens after the 365? Does PayPal send a reminder or do transactions fail silently?
What's the longest period a certificate can be valid for?
Thanks
How do you solve the 406 Not Acceptable [http://localhost/journals.js?search=Ab] error? I assume is some sort of routing problem.
chris, try this:
page << "if ($('flash_notice')) {"
page[:flash_notice].show
page.replace_html :flash_notice, flash[:notice]
page << "} else {"
page.insert_html :before, :new_comment_form, content_tag(:div, flash[:notice], :id => "flash_notice")
page << "}"
page.delay(1) do
page[:flash_notice].hide
end
flash.discard
@Jean-Marc
HTML/CSS -> PDF is hard and the only solutions that I know of that work reliable are Prince XML (expensive) and HTMLDOC (GPL, and not very flexible)
However, for basic styling needs, you might be able to get some love out of prawn-format:
http://jamis.github.com/prawn-format/
This is for Rails 2.3.2 correct? I've got it running here and can't get the batch methods to work, instead I'm getting an undefined method exception when calling ModelName#each.
Ryan, this is awesome. Can you also over SSL Certificates and how to integrate them with your application when processing credit cards? that would be awesome.
Thanks for the episode!
I was curious how to output unicode characters into the pdf, until found it to be really easy - what matters is only the font file, which can be put somewhere under rails root and pointed by pdf.font method.
http://pastie.org/419177
Hi Ryan,
Great podcast (as usual)... I got to say that although I love the fact that it is easier to generate PDF files I'm kinda torn by the need to "code" the actual look and feel of that PDF file whereas with web application we get the benefit of the CSS and such.
Any idea on how we could use an approach similar to HTML+CSS when generating our PDF?
Hello Ryan,
Great screencast!
I creating a simple shopping cart, where you can add / remove itens, but since the field have the same name because :index => nil, the observe_field I have is not working.
Does anyone have some tip on using oberve_field here?
Thanks!
Luciano
I noticed that this works only when application.html.erb layout is used. If using something other than that and in your controller saying layout 'some_layout' it will render js.erb in HTML.
Is this a bug or a feature? or am I doing something wrong?
I am using rails 2.2.2
really good
Thanks Ryan.
Hi guys,
When I have the 2 models : product and category done and the table categories_products ready, how do I proceed with it?
if I have p = @product.first
and p.categories.size gives me the correct count BUT how do I make new relation between the existing category and product.
p.categories.new attempts to create the category?
Thanks
I'm tryin' to install plugin, but got this error:
Plugin not found: ["git://github.com/thorny-sun/prawnto.git"]
(Rails 2.3.2, Ruby 1.9.1p0)
i am running into the problem mentioned above in comment #49. My response is being rendered in HTML per the default layout. How do you stop that?
that is my response is being returned as HTML with the js code embedded.
Thanks! I've got to say I really like the plugin screencasts, like this one, a lot more than the new rails features ones!
I second the thanks. Your screen casts are the coolest way to learn.
Thank you Ryan for all the screen casts :)
Hi,
very usefull tutorial. works *nearly* well in development and production.
I discovered one problem. My setup on the server (not local pc):
production: foo.com
development: foo.bar (my laptop is configured with /etc/hosts: 1.2.3.4 foo.bar.
works fine, but the caching of firefox or passenger (not sure which) leads to the result that a request to foo.bar delivers content from production database and visa versa. Depens which url I used before.
restarting apache and/or empty the firefox cache solves the problem. But it is still annoying.
Cheers -- jerik
Hi Mark, Thanks. I was using the make_resourceful plugin and didn't think i needed the format.pdf option.
Thanks for your help
@Rajesh
You need to have "format.pdf" in your controller for the method you're doing this on. Like Ryan said earlier, you only need that if you already have a format block in your controller already.
For some reason my PDF is not rendering. in my log i get "406 Not Acceptable" error.
i've tried it with Rails 2.3.1 & 2.3.2.
Please help.
Ryan,
Any update on making this work in IE. It also did not work on safari/widnows for me.
Great screencast, Ryan! Very timely for me, as I was implementing this very thing in one of my apps last week. If Prawto's documentation had been _half_ as easy to understand as this, it would have saved me a lot of frustration. :)
Thank you for this (as usual) amazing screencast.
I have a question. Is there a way (with Javascript maybe ?) to send to the printer the pdf, directly from the web page (and not generate the PDF and select "print" on the PDF reader) ?
What I want is more or less a button (or hyperlink) on a webpage called "print". It generates pdf but it is hided to the user.
@mephux, I should have clarified this in the screencast. If you already have a respond_to block in the controller, then you will need to add a format.pdf line. Otherwise Rails should automatically handle this.