If you are having trouble getting the aspect ratio correct on Heroku, try adding a bang ("!") to the end of the geometry string in the crop_command method.
e.g. " -crop '...!'"
From the ImageMagick manual "Width and height emphatically given, original aspect ratio ignored", http://www.imagemagick.org/script/command-line-processing.php#geometry
I was looking around for a simple calendar solution, and this helps a lot! Had some difficulties using Time.now for comparison, and then realized I needed to use Time.zone.now instead, because local time zones were set. Works great now. Thanks Ryan.
I think there is a fundamental difficulty using Date.parse for input from informal text date fields in ruby 1.9.1 and later. In particular, in Ruby 1.9.1:
Date.parse("1/2/03") is February 2, 2001.
Date.parse("1/2/2003") is February 1, 2003.
Ugh! A quick breeze suggests that this was not accidental or a bug. In other words, don't use Date#parse in Ruby 1.9.
And no amount of attempts at localization seemed to get me the desired result for an american date-picker text field. In my last Rails3/1.9.1 experiment, I used a mock-field (:mmddyy_date), defining mmddyy_date= methods, and Date.strptime(string, "%m/%d/%Y") [always inside a begin-rescue-end].
So Date input text fields are getting a bit tricky, particularly in forms. Is there a more elegant solution?
Interestingly I needed a calendar in both of my current client projects: http://radiopodcast.fr has one in the "ma programmation" section, where I used #6 (week) in http://www.webdesignbooth.com/9-useful-jquery-calendar-and-date-picker-plugins-for-web-designers/ (Very usefull URL) and in the backend of http://sevensnap.com we also needed one so I used http://github.com/dmix/weekly_builder which is based on the demoed table_builder.
Thanks for your amazing podcast Ryan. I'm one of those who got into Rails (and Unobstrusive Javascript) thanks to you.
forgot to mention in my previous comment, had good success with this, though evidently the original author has found maintaining the project too time consuming:
http://wiki.github.com/robmonie/jquery-week-calendar/
I ran across Full Calendar recently but have not had time to work with it. Seems excellent from what I have seen.
I agree with Daniel T, Full Calendar is really great. We used it for a full featured calendar function in a localized Rails app. Fast and easy to connect to a JSON-driven web service.
many thanks for this very, very helpful episode(s).
There is only one problem left, I am struggling with:
While working in the sandbox, I seem to have the same problem as "ariel" in post 19 and 20.
When I hit the "return to the shop" button, I get the whole data from paypal in the browsers comman_line.
I have tried to set the variable rm yet to "1" (then it should be a get instead of a post request according to the paypal api). But I still see all the data in the browser being submitted.
Either, this is a Sandbox problem, or I am passing the variable rm in the wrong "place":
Should I pass this variable in the cart.rb (paypal_encrypted method) along with all the other parameters to paypal?
Or must this value ne passed as a parameter directly with the return_url in the checkout_form (similar to thme secret parameter)?
Or is there another mistake?
And: Should the values of the variable rm be passed as an integer or a "string"?
By the way: the return parameter is set, so this cannot be the problem...
Many thanks!
I could have used this about 6 months ago! Great stuff. In my case, I had fewer options for a date entry widget because I needed a widget which could select both date AND time. And with my preferred jQuery. The jQuery UI item doesn't handle time. I found this adaption of Harper's Calendar Date Select to be a solid solution:
http://github.com/railssignals/jquery_calendar_date_select
Ryan,
This is great! Please consider doing more jQuery UI related screencasts especially in the Rails context. I am trying to apply jQuery to Rails and this is a huge help.
Regards,
Bharat
I have implemented a similar situation, however, I have a "Copy" facility. In your domain, this would create a new Project based on an existing one, and new Tasks based on existing ones too.
However, I can create a new Project, but not new Tasks - how do I achieve this?
Thanks for this screencast! I actually ended up writing my own calendar helper in a rails app I wrote some time ago. I needed alot of ajax functionality for adding events and stuff so using a allready build helper wasn't suited for my needs . It's actually quite easy to make your own calendar, just combine date and time methods that rails already provide you with.
got as far as needing "rvm package install openssl" for Ubuntu and tried again. No luck. Can make the Rails3b game model but localhost:3000 shows nothing under localhost:3000/games/new or anything else with webrick spouting a ton of errors. Also fails with thin start (my preference).
localhost:3000 shows up, but the link only shows a horizontal yellow line and not all the gems being used.
why can't I just add new answer field using jQuery by duplicating the previous one (+maybe changing some numbers in id) and then submit the whole form? can't I avoid the helper method link_to_add_fields ? thanks
newbie question: why ryan uses survey_id:integer and question_id:integer when generating models and not survey:references and question:references. what is the difference? thanks
OK, I figured it out: Let say I have a modeless controller, "MymodelessController" with some_action action. 1. In MymodelessController class use instead of load_and_authorize_resource ,
authorize_resource :resource => :mymodeless
2. in ability.rb refer to it as: if user.role?(:power_user) can :some_action, :mymodeless Thanks Ryan, indeed, a great plugin!!!
Hi, could anyone guide me how to solve this problem. I have two models (person & job) which i need to index, it works fine when i index only one but when both of the models are indexed (when raking index), i get the following errors:
using config file '/var/www/nimbus-developer/config/development.sphinx.conf'...
ERROR: section 'job_extra_core_0' (type='source') already exists in /var/www/nim
bus-developer/config/development.sphinx.conf line 60 col 1.
FATAL: failed to parse config file '/var/www/nimbus-developer/config/development
.sphinx.conf'
One gotcha that bit me was not having actionmailer configured to use sendmail. config.action_mailer.delivery_method = :sendmail in the environment.rb, and everything worked.
Now I'm trying to figure out why it's not reading the configuration changes -- all my e-mails are coming from please-change-me!
@chetu - Why would you do that? If you only need to track which userid you currently want to assume, then why not just put the user into the ession - and be finished. Just because you have a golden hammer (authlogic), does not mean everything is a nail. ;-)
@hakunin: not quite. Arel adds some extensions to object via mixins, true (to_sql for example) but Ryan wants an ActiveRecord::Relation, which is different.
Good screencast, Ryan. I can't wait until Ruby 1.9 becomes the standard -- supporting 1.8.x while still taking advantage of some of the goodies that 1.9 dangles in front of us is a real pain.
For another neat trick afforded by BasicObject, see the writeup I did on BasicObject#I at http://metautonomo.us/2010/04/10/ruby-1-9-basicobject-and-not/, too. :)
Sorry, I posted my website url wrongly in the previous comment.
And to add something to the previous comment (and not being suspected as spammer) I may add that the only thing that's left for me to confirm this, is to test my code in Rails 2.3.x, but unfortunately the project I'm working on is already being mounted on Rails 3 and already absolutely dependant on it. I may extract the relevant parts and test it on Rails 2.3.x to see if it works.
Very dissapointing. I may be doing something wrong, but I have checked this from every possible angle and I guess it's Rails 3 fault. Actually, I removed the accepts_nested_attributes_for call from the model and submitted the form and I got exactly the same error.
If you are having trouble getting the aspect ratio correct on Heroku, try adding a bang ("!") to the end of the geometry string in the crop_command method.
e.g. " -crop '...!'"
From the ImageMagick manual "Width and height emphatically given, original aspect ratio ignored", http://www.imagemagick.org/script/command-line-processing.php#geometry
I was looking around for a simple calendar solution, and this helps a lot! Had some difficulties using Time.now for comparison, and then realized I needed to use Time.zone.now instead, because local time zones were set. Works great now. Thanks Ryan.
Sorry, in the previous message:
Date.parse("1/2/3") is February 3, 2001.
Date.parse("1/2/2003") is February 1, 2003.
of course in Ruby 1.8.7, it was different:
Date.parse("1/2/3") is January 2, 3
Date.parse"(1/2/2003") is January 2, 2003
Go figure
I think there is a fundamental difficulty using Date.parse for input from informal text date fields in ruby 1.9.1 and later. In particular, in Ruby 1.9.1:
Date.parse("1/2/03") is February 2, 2001.
Date.parse("1/2/2003") is February 1, 2003.
Ugh! A quick breeze suggests that this was not accidental or a bug. In other words, don't use Date#parse in Ruby 1.9.
And no amount of attempts at localization seemed to get me the desired result for an american date-picker text field. In my last Rails3/1.9.1 experiment, I used a mock-field (:mmddyy_date), defining mmddyy_date= methods, and Date.strptime(string, "%m/%d/%Y") [always inside a begin-rescue-end].
So Date input text fields are getting a bit tricky, particularly in forms. Is there a more elegant solution?
Doesn't work with Rails 3, it fails with the safe html. any ideas?
Good tool to have.
There are also some open source sample scripts at
http://www.biterscripting.com/samples_internet.html
I use them often.
oh, nice service.
Interestingly I needed a calendar in both of my current client projects: http://radiopodcast.fr has one in the "ma programmation" section, where I used #6 (week) in http://www.webdesignbooth.com/9-useful-jquery-calendar-and-date-picker-plugins-for-web-designers/ (Very usefull URL) and in the backend of http://sevensnap.com we also needed one so I used http://github.com/dmix/weekly_builder which is based on the demoed table_builder.
Thanks for your amazing podcast Ryan. I'm one of those who got into Rails (and Unobstrusive Javascript) thanks to you.
Thank you very interesting html-codes. well done my friend
forgot to mention in my previous comment, had good success with this, though evidently the original author has found maintaining the project too time consuming:
http://wiki.github.com/robmonie/jquery-week-calendar/
I ran across Full Calendar recently but have not had time to work with it. Seems excellent from what I have seen.
I agree with Daniel T, Full Calendar is really great. We used it for a full featured calendar function in a localized Rails app. Fast and easy to connect to a JSON-driven web service.
Great screencast!! I would really like to see how time could be manage in this app. Thanks!
I really like FullCalendar: http://arshaw.com/fullcalendar/
i have to agree with #8... for a few episodes, the codecs mess up VLC and playback is completely stuck
Dear Ryan,
many thanks for this very, very helpful episode(s).
There is only one problem left, I am struggling with:
While working in the sandbox, I seem to have the same problem as "ariel" in post 19 and 20.
When I hit the "return to the shop" button, I get the whole data from paypal in the browsers comman_line.
I have tried to set the variable rm yet to "1" (then it should be a get instead of a post request according to the paypal api). But I still see all the data in the browser being submitted.
Either, this is a Sandbox problem, or I am passing the variable rm in the wrong "place":
Should I pass this variable in the cart.rb (paypal_encrypted method) along with all the other parameters to paypal?
Or must this value ne passed as a parameter directly with the return_url in the checkout_form (similar to thme secret parameter)?
Or is there another mistake?
And: Should the values of the variable rm be passed as an integer or a "string"?
By the way: the return parameter is set, so this cannot be the problem...
Many thanks!
I could have used this about 6 months ago! Great stuff. In my case, I had fewer options for a date entry widget because I needed a widget which could select both date AND time. And with my preferred jQuery. The jQuery UI item doesn't handle time. I found this adaption of Harper's Calendar Date Select to be a solid solution:
http://github.com/railssignals/jquery_calendar_date_select
Ryan,
This is great! Please consider doing more jQuery UI related screencasts especially in the Rails context. I am trying to apply jQuery to Rails and this is a huge help.
Regards,
Bharat
Formtastic + calendar_date_select = http://github.com/dyohi/formtastic_calendar_date_select
I have created a progressive enhanced version to use jQueryUI calendar with the current rails date_select
http://gist.github.com/396057
In answer to my own question, I think the key is this line of code:
tasks.reject(&:new_record?).each do |task|
I don't want to throw away any tasks that are already there, but add them to the database instead, with new keys.
Any ideas?
Very useful Screencast, but I have one question.
I have implemented a similar situation, however, I have a "Copy" facility. In your domain, this would create a new Project based on an existing one, and new Tasks based on existing ones too.
However, I can create a new Project, but not new Tasks - how do I achieve this?
Thanks for this screencast! I actually ended up writing my own calendar helper in a rails app I wrote some time ago. I needed alot of ajax functionality for adding events and stuff so using a allready build helper wasn't suited for my needs . It's actually quite easy to make your own calendar, just combine date and time methods that rails already provide you with.
I've used jquery-ui datepicker in projects. if a dom contains a datepicker, it couldn't handle correct when i clone this dom use jquery.
asd
got as far as needing "rvm package install openssl" for Ubuntu and tried again. No luck. Can make the Rails3b game model but localhost:3000 shows nothing under localhost:3000/games/new or anything else with webrick spouting a ton of errors. Also fails with thin start (my preference).
localhost:3000 shows up, but the link only shows a horizontal yellow line and not all the gems being used.
any ideas?
Hi,
I second @Nicolás Hock question. How to redirect from /episodes/63 to /episodes/63-name.. in order to avoid caching duplicate pages.
Ryan, is this what you mean by using the "capture" method?
Rail2 and Rails3 beta3 process <%= '<h1>hello</h1>' %> differently.
Rails3 must use <%= capture {'<h1>hello</h1>'} %> to get the same
result as Rails2
Is this intentional or is it a bug?
why can't I just add new answer field using jQuery by duplicating the previous one (+maybe changing some numbers in id) and then submit the whole form? can't I avoid the helper method link_to_add_fields ? thanks
@creston
see here for SSL logins: http://gist.github.com/393520
newbie question: why ryan uses survey_id:integer and question_id:integer when generating models and not survey:references and question:references. what is the difference? thanks
great article my friend
Thank You, Ryan, for another great screencast.
OK, I figured it out: Let say I have a modeless controller, "MymodelessController" with some_action action. 1. In MymodelessController class use instead of load_and_authorize_resource ,
authorize_resource :resource => :mymodeless
2. in ability.rb refer to it as: if user.role?(:power_user) can :some_action, :mymodeless Thanks Ryan, indeed, a great plugin!!!
Hi,
I have a problem:
---
In view blog/show.html.erb
<div id="comments">
<% for comment in @comments %>
<div class="comment">
<%= simple_format comment.comment %>
</div>
<% end %>
</div>
<h2>New Comment</h2>
<% form_for [@commentable, Comment.new] do |f| %>
<p>
<%= f.label :comment %>
<%= f.text_area :comment, :size => '25x5' %>
</p>
<p><%= f.submit 'Submit' %></p>
<% end %>
---
After create the submit redirect_to blog/:id/comments
how redirect_to blog/:id ??
Best Regards.
Thanks!!
Great plugin! One question: how can it be applied to a controller that have no model?
thanks for this nice code & template
great video, thank you.
Hi, could anyone guide me how to solve this problem. I have two models (person & job) which i need to index, it works fine when i index only one but when both of the models are indexed (when raking index), i get the following errors:
using config file '/var/www/nimbus-developer/config/development.sphinx.conf'...
ERROR: section 'job_extra_core_0' (type='source') already exists in /var/www/nim
bus-developer/config/development.sphinx.conf line 60 col 1.
FATAL: failed to parse config file '/var/www/nimbus-developer/config/development
.sphinx.conf'
Your help is much appreciated!
Hey Guys, I'm getting the following errors in Rails 2.3.5 and gte the following error when trying to access the RAND method the way Ruan does..
undefined method `RAND'
Any ideas?
One gotcha that bit me was not having actionmailer configured to use sendmail. config.action_mailer.delivery_method = :sendmail in the environment.rb, and everything worked.
Now I'm trying to figure out why it's not reading the configuration changes -- all my e-mails are coming from please-change-me!
Thanks again!
@chetu - Why would you do that? If you only need to track which userid you currently want to assume, then why not just put the user into the ession - and be finished. Just because you have a golden hammer (authlogic), does not mean everything is a nail. ;-)
Thanks for this Ryan and all the other great casts you have done.
Have you managed to get this excellent gem to work with Rails3, I cant seem to get rid of the undefined method semantic_form_for error
@hakunin: not quite. Arel adds some extensions to object via mixins, true (to_sql for example) but Ryan wants an ActiveRecord::Relation, which is different.
thank you for this, its helps me alot...
i got one question, how will i apply it to multiple forms in one page?
thanks!
I ran this episode's project both on rails 2.3.5 and rails 3.0.0.beta3 and it works great, so I guess it's me. I'm shocked :-O
Good screencast, Ryan. I can't wait until Ruby 1.9 becomes the standard -- supporting 1.8.x while still taking advantage of some of the goodies that 1.9 dangles in front of us is a real pain.
For another neat trick afforded by BasicObject, see the writeup I did on BasicObject#I at http://metautonomo.us/2010/04/10/ruby-1-9-basicobject-and-not/, too. :)
Sorry, I posted my website url wrongly in the previous comment.
And to add something to the previous comment (and not being suspected as spammer) I may add that the only thing that's left for me to confirm this, is to test my code in Rails 2.3.x, but unfortunately the project I'm working on is already being mounted on Rails 3 and already absolutely dependant on it. I may extract the relevant parts and test it on Rails 2.3.x to see if it works.
Hay @Shai, I was following this tutorial in Rails 3 and it is broken indeed. I get a ActiveRecord::AssociationTypeMismatch with the message
User(#11741180) expected, got ActiveSupport::HashWithIndifferentAccess(#3929460)
Very dissapointing. I may be doing something wrong, but I have checked this from every possible angle and I guess it's Rails 3 fault. Actually, I removed the accepts_nested_attributes_for call from the model and submitted the form and I got exactly the same error.
FYI: Method #scoped is not necessary since
MyModel.ancestors.map(&:to_s).grep /Arel/ # => ["Arel::Sql::ObjectExtensions", "Arel::ObjectExtensions"]
This means that MyModel class acts as a relation itself, and #where could be called on it directly.
Is this broken in Rails 3 for anyone?