Though, perhaps the better way to look at this is to render one massive pdf of the index template with some special formatting and page breaks instead of 500 show template pdfs.
How possible is it to have Rails automatically save a copy of this pdf on the server? I need a confirmation sheet for our folks in the office to use and I'd prefer to not have to do them one at a time if possible.
hm, pdfkit seems quite nice. But in a simple test umlauts weren't displayed correctly with wkhtmltopdf =/
I don't have the time to figure this out for now.
Regarding my previous question about datepicker not working for dynamically generated datepicker fields, I finally solved it in case anyone had the same problem:
Regarding my previous question about datepicker not working for dynamically generated datepicker fields, I finally solved it in case anyone had the same problem:
I have an issue when I generate the datepicker textfield on the fly as shown in episode 197 - nested models form. The newly generated datepicker fields are not working. Anyone know how to fix that?
@jonas, why? Rails does this in a similar way. Except all it does is check for protected attributes that shouldn't be mass assigned first and that the object responds to "#{key}=". If you want to add your own ability to have protected attributes, then go for it. I just don't think that's in the scope of this railscast.
Thanks Ryan for the great post.
I've implemented same in my app. But I've problem when I'm using select box in nested.
My problem is the selected value is not showing in edit.
my select box is like this
<%= f.select(:update_attribute_id,options_for_select([["feature_coach", "67"], ["feature_postbox", "4"], ["feature_audit", "5"], ["employee_model", "6"]]),:class=>"formtextbox") %>
in edit it always shows the first option only. If I pass the id's which is collected form table in arrays like
<%= f.collection_select(:update_attribute_id,options_for_select([["feature_coach", "67"], ["feature_postbox", "4"], ["feature_audit", "5"], ["employee_model", "6"]],[5,6,4]),:class=>"formtextbox") %>
then it shows first id as selected, if i do each then in a single row all the selected will show in seperated box. How could I solve this.
Your input will be very helpful. Thanks in advance.
Using the migration (as amended 03/29/08 - blog no longer available) on a large database took a very long time.
Actually, using tasks.count in Rails 2.3 works so:
Project.reset_column_information
Project.find(:all).each do |p|
b.update_attribute :tasks_count, p.tasks.count
end
Is now fine and runs fast enough on a reasonable database size. But make sure this is run before setting counter_cache in the model.
Because once set, tasks_count will become read only and won't update.
I am guessing that Rails was modified so that using count always references the tasks table and to use the cached value you directly read tasks_count. But there seems no reference to this in the API.
But for very large databases, an sql updater to set this column would probably be better.
Anyway i found a problem using prawn: i made a table and i cannot manage to have bold text inside the table.
i tried putting a cell and it works in some ways, but i need single words to be formatted separately.
Would also like response to dhc question. From some angles it looks like Rails 3 has a lot of features that come as a box of d-i-y components which you have to know how to assemble youself.
I experience some strange behaviours when playing around with this multistep form. Sometimes, when pressing back to change a step, it jumps two steps forward when pressing next afterwards. Somebody else who sees this in his form?
Is it possible to just inherit from ActiveModel::Base?
If so, is there any good reason not to do this, instead of picking and choosing modules and having to dig through code to figure out which dependencies are missing?
@Sean - the shared folder gets created when you run cap deploy:setup. I'm not sure how the database.yml file got there though. If there isn't an automatic way to upload files in the shared folder, my guess is that ryan uploaded it there (via ftp or the like).
Small caveat: ActiveModel defines before_validate and after_validate callbacks, but these aren't really usable: they're mixed up with the validations themselves, and invoked in the order they were defined. So, for example, if you declare a before_validate callback after a validates_presence_of, the before_validate will be called *after* the validation, which isn't very useful.
There's a change in edge now that moves before_validation and friends from ActiveRecord to ActiveModel to fix this, so expect that to make it to the release candidate.
Thank you so much, it was just what I was looking for!
Although I have so problems that I had fix:
- didn't recognized <% title "New Order" %> so I had to run script/generate nifty_layout
- I got this error:
Missing template shipping_step.erb in view path .../app/views:
so I have to put <%= render :partial => "#{@order.current_step}_step", :locals => { :f => f } %> in new.html.erb
- render "new" didn't work for me either, changed to ender :action => 'new'
-for first_step? and last_step? : self.current_step, didn't work with only current_step
I just read this "You no longer need to place a minus sign at the end of a ruby interpolation inside an ERb template to remove the trailing carriage return in the HTML output."
http://guides.rails.info/3_0_release_notes.html
And how do you do unit tests? If you have a partial which is one of these semantic_form_for, how the blazes do you run renderizer so that it works, hm?
Like Jason mentioned, you can also use Devise 1.1.rc2. This helped me solve an 'uninitialized constant UsersController' error at /sign_up.
Curious to know if anybody has tried creating a table including images?
How do you add an image with fixed dimensions as well as create a thumbnail? so you can click on the thumbnail and view the bigger image
Though, perhaps the better way to look at this is to render one massive pdf of the index template with some special formatting and page breaks instead of 500 show template pdfs.
How possible is it to have Rails automatically save a copy of this pdf on the server? I need a confirmation sheet for our folks in the office to use and I'd prefer to not have to do them one at a time if possible.
hm, pdfkit seems quite nice. But in a simple test umlauts weren't displayed correctly with wkhtmltopdf =/
I don't have the time to figure this out for now.
This is fantastic. Prawn drives me nuts.
A great gem! I love that it can be used as middleware! Thanks so much for the screencasts!
Hi Ryan,
Thanks for the tutorial. How do we do the functional testing with subdomain?
Ryan,
Great stuff. The episode came sooner than I expected.
Thanks.
- Jermaine
Awesome with a capital A, I have been waiting for a library like this for ages.
Ryan, great job as usual. I was already planning to check out those gems during these days so the timing of this screencast is just perfect.
and what about epub?
any gem preferences?
thanks for your excellent work.
Thanks very much for the episodes and best wishse.
Thanks ryan.
It works well.
By
Mohamed
Regarding my previous question about datepicker not working for dynamically generated datepicker fields, I finally solved it in case anyone had the same problem:
// application.js
$(function() {
$('.datepicker').live('focus', function() {
$(this).datepicker({dateFormat: 'dd M yy',
showOtherMonths: true,
selectOtherMonths: true,
changeMonth: true,
changeYear: true});
});
});
Regarding my previous question about datepicker not working for dynamically generated datepicker fields, I finally solved it in case anyone had the same problem:
<script src='http://pastie.org/1018775.js'></script>
Just an idea, totally unrelated to the screencast.
You could make a good use of p2p and give torrent links among with the usual download links.
As I said before, great episode. However, I've no idea how to change first day of a week. Help please!
what does this mean?
I have an issue when I generate the datepicker textfield on the fly as shown in episode 197 - nested models form. The newly generated datepicker fields are not working. Anyone know how to fix that?
@jonas, why? Rails does this in a similar way. Except all it does is check for protected attributes that shouldn't be mass assigned first and that the object responds to "#{key}=". If you want to add your own ability to have protected attributes, then go for it. I just don't think that's in the scope of this railscast.
http://github.com/rails/rails/blob/master/activerecord/lib/active_record/base.rb#L1532
Thanks Ryan for the great post.
I've implemented same in my app. But I've problem when I'm using select box in nested.
My problem is the selected value is not showing in edit.
my select box is like this
<%= f.select(:update_attribute_id,options_for_select([["feature_coach", "67"], ["feature_postbox", "4"], ["feature_audit", "5"], ["employee_model", "6"]]),:class=>"formtextbox") %>
in edit it always shows the first option only. If I pass the id's which is collected form table in arrays like
<%= f.collection_select(:update_attribute_id,options_for_select([["feature_coach", "67"], ["feature_postbox", "4"], ["feature_audit", "5"], ["employee_model", "6"]],[5,6,4]),:class=>"formtextbox") %>
then it shows first id as selected, if i do each then in a single row all the selected will show in seperated box. How could I solve this.
Your input will be very helpful. Thanks in advance.
Using the migration (as amended 03/29/08 - blog no longer available) on a large database took a very long time.
Actually, using tasks.count in Rails 2.3 works so:
Project.reset_column_information
Project.find(:all).each do |p|
b.update_attribute :tasks_count, p.tasks.count
end
Is now fine and runs fast enough on a reasonable database size. But make sure this is run before setting counter_cache in the model.
Because once set, tasks_count will become read only and won't update.
I am guessing that Rails was modified so that using count always references the tasks table and to use the cached value you directly read tasks_count. But there seems no reference to this in the API.
But for very large databases, an sql updater to set this column would probably be better.
instead of including ActiveModel::Conversion module, extending ActiveModel::Naming module, and defining the persisted? method...
Another option would have been to change the form_for call in the view. Just change "form_for @message" to "form_for :message, :url => messages_path"
Hi,
Why is it that I can submit a form only once?
I think it's because the security_tags aren't update, but I don't know how to get around that.
Any advice?
Thank you
There is newer version of vestal_versioned.
Some changes:
To install it add:
config.gem 'vestal_versions'
And there is no need for adding migration to get version 1 for existing records.
I think this is very dangerous...
send("#{name}=", value)
Hi,
good job as always Ryan.
Anyway i found a problem using prawn: i made a table and i cannot manage to have bold text inside the table.
i tried putting a cell and it works in some ways, but i need single words to be formatted separately.
is there any way to do that?
thanks in advance
Would also like response to dhc question. From some angles it looks like Rails 3 has a lot of features that come as a box of d-i-y components which you have to know how to assemble youself.
Surely this wasn't the point of Rails?
About doing that for nested objects, if the query has :include or :joins.
i have tried to do this and it worked 'test_nested.test_id'.to_sym => 1
Any problems that may come from that?
Thanks for the screen screen casts, which i really the lighthoue for any new comer.
I experience some strange behaviours when playing around with this multistep form. Sometimes, when pressing back to change a step, it jumps two steps forward when pressing next afterwards. Somebody else who sees this in his form?
Thanks for the great example
Threw it into a gem if anyone is interested
http://rubygems.org/gems/config-file-loader
I was having trouble getting this to work (on Rails 3). This helped http://millarian.com/programming/ruby-on-rails/rails-counter_cache-problem/
Is it possible to just inherit from ActiveModel::Base?
If so, is there any good reason not to do this, instead of picking and choosing modules and having to dig through code to figure out which dependencies are missing?
OK body.
Thanks
Thank you friends,
@Sean - the shared folder gets created when you run cap deploy:setup. I'm not sure how the database.yml file got there though. If there isn't an automatic way to upload files in the shared folder, my guess is that ryan uploaded it there (via ftp or the like).
Small caveat: ActiveModel defines before_validate and after_validate callbacks, but these aren't really usable: they're mixed up with the validations themselves, and invoked in the order they were defined. So, for example, if you declare a before_validate callback after a validates_presence_of, the before_validate will be called *after* the validation, which isn't very useful.
There's a change in edge now that moves before_validation and friends from ActiveRecord to ActiveModel to fix this, so expect that to make it to the release candidate.
Very cool! I'd like to see more OM's in the NoSQL world to start using this, instead of cooking up their own!
I already have the user model.
How should I use Devise to integrate it with legacy system?
Thanks in advance.
Nice episode.
Wouldn't a better name for "layout.html.erb" be "layout.html.erb.erb"?
Tebrikler arkadaşlar
Thank you so much, it was just what I was looking for!
Although I have so problems that I had fix:
- didn't recognized <% title "New Order" %> so I had to run script/generate nifty_layout
- I got this error:
Missing template shipping_step.erb in view path .../app/views:
so I have to put <%= render :partial => "#{@order.current_step}_step", :locals => { :f => f } %> in new.html.erb
- render "new" didn't work for me either, changed to ender :action => 'new'
-for first_step? and last_step? : self.current_step, didn't work with only current_step
Hi Ryan
I just read this "You no longer need to place a minus sign at the end of a ruby interpolation inside an ERb template to remove the trailing carriage return in the HTML output."
http://guides.rails.info/3_0_release_notes.html
Keep the Rails 3 ones coming.
Thanks
Ben
another couple of extremely useful railscasts Ryan :) (this and part 1) keep up the good work.
And how do you do unit tests? If you have a partial which is one of these semantic_form_for, how the blazes do you run renderizer so that it works, hm?
No unit testing examples, no TDD. Pity.
Will be really cool the refactoring of the controller :)
Taking out "countrySelected();" in the amended javascript makes this work for my app on rails 2.0.2.
I would like to filter the states list by the pre-selected country though. What might I be missing?
FYI to use device in Rails3 you now need to update your gem to gem "devise", :git => "git://github.com/plataformatec/devise.git"