I whole heartedly thank you for the community service that you are doing. And many congratulations for completing 3 yrs on it and still going :)
A small request from my side. Please consider doing a screencast on has_many_polymorphs
Hi! Google gerade im Web und bin auf dieser Homepage gelandet.
Respekt, haben Sie toll gemacht.
Ich wünsche Ihnen weiterhin viel Erfolg mit Ihre Seite und natürlich viele Besucher.
Hier habe ich mich sehr wohl gefühlt und werde wieder hierher zurückkommen.
Freue mich auf einen Gegenbesuch auf meiner Homepage
If you're using S3 as a storage mechanism, you can't use the avatar_geometry method as shown (it assumes a local file). Paperclip can convert from S3 file to local TempFile with the `Paperclip::Geometry.from_file`: http://gist.github.com/339380
Thank you for your great screencasts! i've already learned A LOT from you!
Unfortunately i got a problem with the cropping process in this screencast:
Everything works fine, the image can get cropped, it even crops the right section and it gets saved...
But then, after saving, the cropped image is in a wrong size. Even though i defined the size to be 100x100# (as in your movie)... It is 167x100 ... an STRECHED..
has anybody got an idea what this could be? i already looked 3 times through all files of this process..
Thanks for your answers! and sorry for my bad english, i'm from switzerland ;)
Though, from a security perspective, this somewhat scares me. I've always considered "cookies vs sessions" to be clientside-variables vs serverside-variables, where sessions were stored serverside and a cookie was used to keep track of the session id only.
Also, worth mentioning is that cookie-based sessions is of course nice if you have multiple servers serving the same content, though, for sensitive data, a database or memcached might be an option. :)
Again, thanks for another lovely case! Keep up the good work! :D
Very very useful plugin!!!
Only one thing I've found...
I got this error:
wrong number of arguments (1 for 0)
app/models/ability.rb:6:in `role?'
app/models/ability.rb:6:in `initialize'
ability.rb (line 6):
if user.role? :admin
user.rb:
def role?
roles.include? role.to_s
end
So the error seems to be in user.rb but no luck :(
Could you help me or say me what's wrong?
Thanks a lot!!!!!
I encountered a problem with the conditions_options method when trying to compare a field to an array of values. The flatten would recursively flatten my argument (an array) and i'd end up with too many options for my conditions. I made the following change:
## MY FIELD
def state_conditions
["state in (?)", state] unless state.to_s.blank?
end
## CHANGED CODE HERE
def conditions_options
opts = []
conditions_parts.each do |condition|
condition[1..-1].each{|cp| opts << cp}
end
opts
end
Other than that, I really liked this approach. I added a few extra methods to use the same model to generate and search through SQL or my SOLR index.
I made a gem called Prowly to send messages to iPhone via Prowl and after that I forked the God project and added it support to send notification via Prowl, so here are the repos: http://github.com/rafmagana/prowly and http://github.com/rafmagana/god
All works great.. However, if I include ":reject_if => lambda { |a| a[:title].blank? }" The fields wont create or update. If I remove the reject_if everything works fine.
Any ideas why the reject_if would break the create or update?
Also, :title is correct.. That is the field in my database..
Ryan, why does the method "load_resource" is called from the method "load_and_authorize_resource" in the "resource_authorization.rb" file?
It was causing me some problems when I try to call a controller without a model like ApplicationController or when I use it to manage a model within an other controller, so I tried to take it out and everything seems to work.
There are no plans to support sortable_elements outside the legacy helper at this time as different frameworks tackle this differently, the amount of markup that would need to be emitted would take away from the cleanliness of the code.
Sortable Elements are easily tackled with javascript inside your javascript files, or by rendering out the javascript in a js.erb file.
I've implemented all the code, but the dynamic menu isn't working - no errors are thrown, but the first selection list has no impact on the second selection list (and the second one isn't even hidden, either).
Is there something different about Rails 2.3.5 that I should consider??
The new Rails 3 binary will actually automagically create all the bare necessary .gitignore and .gitkeep files you may need. It does this by default, but you can opt-out of creating them by passing -G as an option on the command line.
Hi, i love nested form bbut i was wondering: how would do you transform your HABTM checkboxes into a nested form, as you have to loop through all categories and check the association with fields_for ?
Just to mention for all the windows users out there: I'm using cygwin (v1.7.1.1) with imagemagick and paperclip works fine. No need to install imagemagick as an extra package. Main development is on a Mac though but cygwin is a good way to work cross-platform.
@Ryan: Thanks for your great screencasts!
I just want to ask, how can I use observe_field for the text_field with dynamically generated id?
Because I want to use live validation, and (I think) to be able to do that I have to get the id of the text_field.
My problem is, how can I get it if it's dynamically generated?
I used Term for a class name but it seems to be incompatible with Cucumber. Thanks for all the podcasts. http://stackoverflow.com/questions/1736747/how-to-resolve-rails-model-namespace-collision
There isn't really a need on the Rails side for observe_field and observe_form anymore so it was deprecated. It is just as much code to setup in your rails helper as to implement yourself in js
You would just use an event listener in your js framework of choice to watch for changes on the form field and perform the ajax call, or whatever action needs to be taken.
As an additional note the way observe_field and observe_form worked prior to rails 3 was inconsistent based on what options you gave it, whether or not it serialized the form, and what value was passed as the query param to your action. Which made the whole idea more complicated then it needed to be. Best to leave it to the developer to slap together some quick js to do the same thing in the same amount of code and intent to be 100% clear.
there is a legacy helper for anyone wanting to still use these pieces in their original form, with inline js.
I'm new to Rails. Love the RailsCasts. Sometimes, even using the Flash.now, I get a one-line blank highlighted line on the next page, reached by using a Nav bar link_to function. The idea is that sometimes the user sees the error message and just bails out to another place in the program using the navigation bar function. The html source of the problem page reads:
<div id="notice"></div><div id="warning"></div>
On Safari on a Mac, this generates a single colored line for each division, containing no text.
I've only been able to eliminate this quirk by adding an "if flash[:error]" check before div & flash lines - obviously not using the cycling method described here and typing many more characters. Any tips would be appreciated.
I am left with one lingering question, which is, how do you get unique labels for each answer and each question? I don't see how to automate tests for this without being able to make unique labels!
Ryan, thanx for all about rails 3
You renewed my excitement for rails espacially with this one.
I cant wait to start experimenting again.
And indeed the delete link has always been a dumb error in rails, too bad it still is. I already used your previous episode as inspiration for a plugin of mine, you can expect an update for rails 3 soon. Github resource_delete
@marcel, I believe many of the official Rails plugins will eventually be upgrade to Rails 3. I assume in_place_edit will, but I recommend asking on the rails-core mailing list. You can probably fork the plugin and contribute to the upgrade as well.
once more a great screencast with exactly the info i need at the moment.
is there also a replacement for the in_place_editing plugin I used with rails 2?
How can i have the in_place_edit function again in rails3 (jquery) ?
many thanks.
You are correct. The reason behind most of these decisions were to allow you to easily implement a driver for whatever framework you choose and the data you look for is consistent.
As well as the ability to easily override behavior.
For example:
jQuery users could easily override the confirm event and use a jQueryUI dialog to do the confirmation rather than using the standard javascript confirm box, or you can override some of the ajax events to open/close things like please wait layers, all of this can be done in a matter of minutes by overriding events.
It truly opens up a lot of areas for customization of standard rails behavior with very little effort.
@Michael there should be no need to update your views manually, when using the helpers provided to you by rails such as :confirm => "Are you sure?" will add these custom attributes for you.
I understand your point with css classes but with the number of Rails applications out there the chances of clashing with css classes people are already using are high so data- attributes were preferred especially being that this is the standard way of doing things like this in HTML 5.
The other debate with using css classes is for things like confirm, changing button text on submit etc, you can't supply data in the css class for those.
Using the data- attributes allows for a lot of versatility with changing the values inside of them etc without needing to swap css classes which will cause repaints and reflows.
Hope this gives a little more insight into the decision.
Great introduction into developing for mobile Ryan. I had been looking for a tutorial like this one for a while! Except I am running into some issues.
I am trying to replicate your tutorial on an existing rails app. Everything looks fine until you try to load the show.mobile.erb. Instead of being loaded into the current page in the mobile layout, it just loads in as is. Any idea why it would be disregarding the layout?
@Michael, I can see your point, especially on "data-remote" because it has no other purpose than to change behavior. In pure UJS the search form would have a "search" id with custom JavaScript to turn it into an AJAX request.
However that does require some custom, application-specific JavaScript which adds an extra step to making a form AJAX in Rails.
I think the aim is finding the benefits of UJS while keeping things as convenient as they were before. Here it is easy to swap out the JavaScript Rails driver which I think is one of the main purposes behind UJS in Rails.
I also had the undefined method 'klass' for nil:NilClass error - turned out I had put the link_to_add_fields inside the partial, rather than on the parent form.
@John, I like the convenience of returning JavaScript directly. Running it through JSON adds another layer of complexity that I don't find necessary.
That said, I have little experience with heavy JavaScript applications, so in those cases it may be cleaner to only use JSON responses and keep the logic/behavior all in one place.
The argument reminds me of YAML vs Ruby code for config files. I generally prefer Ruby code for configuration because of the additional power it brings. It works really well as long as that power isn't abused.
What is your opinion on the idea that executing remote received javascript is a bad idea as well and that we should stick to passing xml/json and replace the content in a callback instead?
Hi Ryan,
I whole heartedly thank you for the community service that you are doing. And many congratulations for completing 3 yrs on it and still going :)
A small request from my side. Please consider doing a screencast on has_many_polymorphs
Thanks!
Hi! Google gerade im Web und bin auf dieser Homepage gelandet.
Respekt, haben Sie toll gemacht.
Ich wünsche Ihnen weiterhin viel Erfolg mit Ihre Seite und natürlich viele Besucher.
Hier habe ich mich sehr wohl gefühlt und werde wieder hierher zurückkommen.
Freue mich auf einen Gegenbesuch auf meiner Homepage
If you're using S3 as a storage mechanism, you can't use the avatar_geometry method as shown (it assumes a local file). Paperclip can convert from S3 file to local TempFile with the `Paperclip::Geometry.from_file`: http://gist.github.com/339380
I am getting:
Couldn't find 'paperclip' generator
What does this mean? Any help would be appreciated and a big thankyou to Ryan! Your screencasts are invaluable.
So many functions.. What they do?
+1 also interesting!
I might be worng but you do not need to escape html in the view now because of safe_buffer in rails3. Isn't that correct?
Hi, Ryan!
I have an error at string svn propset svn:ignore "*.sqlite3" db/
What is wrong?
Thanx!
Thank you for your great screencasts! i've already learned A LOT from you!
Unfortunately i got a problem with the cropping process in this screencast:
Everything works fine, the image can get cropped, it even crops the right section and it gets saved...
But then, after saving, the cropped image is in a wrong size. Even though i defined the size to be 100x100# (as in your movie)... It is 167x100 ... an STRECHED..
has anybody got an idea what this could be? i already looked 3 times through all files of this process..
Thanks for your answers! and sorry for my bad english, i'm from switzerland ;)
Question: Does it work with Rails 3 ?
Thanks for a nice cast!
Though, from a security perspective, this somewhat scares me. I've always considered "cookies vs sessions" to be clientside-variables vs serverside-variables, where sessions were stored serverside and a cookie was used to keep track of the session id only.
Also, worth mentioning is that cookie-based sessions is of course nice if you have multiple servers serving the same content, though, for sensitive data, a database or memcached might be an option. :)
Again, thanks for another lovely case! Keep up the good work! :D
Very very useful plugin!!!
Only one thing I've found...
I got this error:
wrong number of arguments (1 for 0)
app/models/ability.rb:6:in `role?'
app/models/ability.rb:6:in `initialize'
ability.rb (line 6):
if user.role? :admin
user.rb:
def role?
roles.include? role.to_s
end
So the error seems to be in user.rb but no luck :(
Could you help me or say me what's wrong?
Thanks a lot!!!!!
I've been playing with Mocha but learning about .build made my life so much simpler!
Thanks yet again!
Ryan,
I encountered a problem with the conditions_options method when trying to compare a field to an array of values. The flatten would recursively flatten my argument (an array) and i'd end up with too many options for my conditions. I made the following change:
## MY FIELD
def state_conditions
["state in (?)", state] unless state.to_s.blank?
end
## CHANGED CODE HERE
def conditions_options
opts = []
conditions_parts.each do |condition|
condition[1..-1].each{|cp| opts << cp}
end
opts
end
Other than that, I really liked this approach. I added a few extra methods to use the same model to generate and search through SQL or my SOLR index.
Good job.
I made a gem called Prowly to send messages to iPhone via Prowl and after that I forked the God project and added it support to send notification via Prowl, so here are the repos: http://github.com/rafmagana/prowly and http://github.com/rafmagana/god
All works great.. However, if I include ":reject_if => lambda { |a| a[:title].blank? }" The fields wont create or update. If I remove the reject_if everything works fine.
Any ideas why the reject_if would break the create or update?
Also, :title is correct.. That is the field in my database..
Thanks for the tutorials, Ryan!!!
Ryan, why does the method "load_resource" is called from the method "load_and_authorize_resource" in the "resource_authorization.rb" file?
It was causing me some problems when I try to call a controller without a model like ApplicationController or when I use it to manage a model within an other controller, so I tried to take it out and everything seems to work.
Thanks.
do:
touch tmp/always_restart.txt
to tell passenger to restart after every request if it becomes annoying to touch tmp/restart.txt during dev mode.
@Cassio
There are no plans to support sortable_elements outside the legacy helper at this time as different frameworks tackle this differently, the amount of markup that would need to be emitted would take away from the cleanliness of the code.
Sortable Elements are easily tackled with javascript inside your javascript files, or by rendering out the javascript in a js.erb file.
What about sortable_elements, for example? In Rails 3 beta it still uses inline javascript. Does anyone knows if this is also likely to change?
I figured it out - I needed to implicitly map.resources :javascripts and remove the map.connect line.
Thanks - works like a charm now!
For Rails 3 check out:
http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/
I made a little (little) tutorial to get ruby-debug run on the last version of ruby
Enjoy
http://thibaut-assus.heroku.com/2010/03/18/rdebug/
Great railscast, as always!
I've implemented all the code, but the dynamic menu isn't working - no errors are thrown, but the first selection list has no impact on the second selection list (and the second one isn't even hidden, either).
Is there something different about Rails 2.3.5 that I should consider??
Thanks!
The new Rails 3 binary will actually automagically create all the bare necessary .gitignore and .gitkeep files you may need. It does this by default, but you can opt-out of creating them by passing -G as an option on the command line.
Hi, i love nested form bbut i was wondering: how would do you transform your HABTM checkboxes into a nested form, as you have to loop through all categories and check the association with fields_for ?
Just to mention for all the windows users out there: I'm using cygwin (v1.7.1.1) with imagemagick and paperclip works fine. No need to install imagemagick as an extra package. Main development is on a Mac though but cygwin is a good way to work cross-platform.
@Ryan: Thanks for your great screencasts!
Hi. Thanks for the great tutorial.
I just want to ask, how can I use observe_field for the text_field with dynamically generated id?
Because I want to use live validation, and (I think) to be able to do that I have to get the id of the text_field.
My problem is, how can I get it if it's dynamically generated?
Please help me.
Thanks
Cece
I used Term for a class name but it seems to be incompatible with Cucumber. Thanks for all the podcasts. http://stackoverflow.com/questions/1736747/how-to-resolve-rails-model-namespace-collision
@assente
There isn't really a need on the Rails side for observe_field and observe_form anymore so it was deprecated. It is just as much code to setup in your rails helper as to implement yourself in js
You would just use an event listener in your js framework of choice to watch for changes on the form field and perform the ajax call, or whatever action needs to be taken.
As an additional note the way observe_field and observe_form worked prior to rails 3 was inconsistent based on what options you gave it, whether or not it serialized the form, and what value was passed as the query param to your action. Which made the whole idea more complicated then it needed to be. Best to leave it to the developer to slap together some quick js to do the same thing in the same amount of code and intent to be 100% clear.
there is a legacy helper for anyone wanting to still use these pieces in their original form, with inline js.
I'm new to Rails. Love the RailsCasts. Sometimes, even using the Flash.now, I get a one-line blank highlighted line on the next page, reached by using a Nav bar link_to function. The idea is that sometimes the user sees the error message and just bails out to another place in the program using the navigation bar function. The html source of the problem page reads:
<div id="notice"></div><div id="warning"></div>
On Safari on a Mac, this generates a single colored line for each division, containing no text.
I've only been able to eliminate this quirk by adding an "if flash[:error]" check before div & flash lines - obviously not using the cycling method described here and typing many more characters. Any tips would be appreciated.
if i dont have a domain then how to send email
... oh and dot forget to add
Paperclip.options[:command_path] = "/usr/local/bin"
to config/environments/development.rb
Nice example, as alwais, but what about "observe_field" in UJS?
Great screencast Ryan!
I am left with one lingering question, which is, how do you get unique labels for each answer and each question? I don't see how to automate tests for this without being able to make unique labels!
thanks.
thanks!!!
Ryan, thanx for all about rails 3
You renewed my excitement for rails espacially with this one.
I cant wait to start experimenting again.
And indeed the delete link has always been a dumb error in rails, too bad it still is. I already used your previous episode as inspiration for a plugin of mine, you can expect an update for rails 3 soon. Github resource_delete
@marcel, I believe many of the official Rails plugins will eventually be upgrade to Rails 3. I assume in_place_edit will, but I recommend asking on the rails-core mailing list. You can probably fork the plugin and contribute to the upgrade as well.
once more a great screencast with exactly the info i need at the moment.
is there also a replacement for the in_place_editing plugin I used with rails 2?
How can i have the in_place_edit function again in rails3 (jquery) ?
many thanks.
@Ryan
You are correct. The reason behind most of these decisions were to allow you to easily implement a driver for whatever framework you choose and the data you look for is consistent.
As well as the ability to easily override behavior.
For example:
jQuery users could easily override the confirm event and use a jQueryUI dialog to do the confirmation rather than using the standard javascript confirm box, or you can override some of the ajax events to open/close things like please wait layers, all of this can be done in a matter of minutes by overriding events.
It truly opens up a lot of areas for customization of standard rails behavior with very little effort.
@Michael there should be no need to update your views manually, when using the helpers provided to you by rails such as :confirm => "Are you sure?" will add these custom attributes for you.
I understand your point with css classes but with the number of Rails applications out there the chances of clashing with css classes people are already using are high so data- attributes were preferred especially being that this is the standard way of doing things like this in HTML 5.
The other debate with using css classes is for things like confirm, changing button text on submit etc, you can't supply data in the css class for those.
Using the data- attributes allows for a lot of versatility with changing the values inside of them etc without needing to swap css classes which will cause repaints and reflows.
Hope this gives a little more insight into the decision.
Great introduction into developing for mobile Ryan. I had been looking for a tutorial like this one for a while! Except I am running into some issues.
I am trying to replicate your tutorial on an existing rails app. Everything looks fine until you try to load the show.mobile.erb. Instead of being loaded into the current page in the mobile layout, it just loads in as is. Any idea why it would be disregarding the layout?
Thanks in advance for any help you can offer.
@Michael, I can see your point, especially on "data-remote" because it has no other purpose than to change behavior. In pure UJS the search form would have a "search" id with custom JavaScript to turn it into an AJAX request.
However that does require some custom, application-specific JavaScript which adds an extra step to making a form AJAX in Rails.
I think the aim is finding the benefits of UJS while keeping things as convenient as they were before. Here it is easy to swap out the JavaScript Rails driver which I think is one of the main purposes behind UJS in Rails.
Try this for the "complete billing address error"
Add the billing_address hash after the ip address.
if credit_card.valid?
response = gateway.purchase(1000, credit_card,
:ip => "127.0.0.1",
:billing_address => {
:name => 'Test User',
:company => '',
:address1 => '123 S Main St',
:address2 => '',
:city => 'Akron',
:state => 'OH',
:country => 'US',
:zip => '44333',
:phone => '(310)555-5555'
}
)
I also had the undefined method 'klass' for nil:NilClass error - turned out I had put the link_to_add_fields inside the partial, rather than on the parent form.
Thanks for the tutorial. It was very usefull for me. :-)
i´m not so familiar with using java scripts but still learning. Try to work with this one Thx.
Ryan, thanks a lot for this great introduction into the use of Javascript in Rails 3.
It does seem to me, however, adding custom tags in order to get javascript functionality running, is not _really_ unobstrusive.
At least not, the way I understand unobstrusive.
It is, after all, _extra_ code added for the single and sole purpose of getting your javascript running.
Maybe this sounds too purist. I am aware of the fact, that at some point, you need to set some "hooks" from where the javascript events take off.
To me, it would have seemed a simpler approach, if one could simply use e.g. css classes, which are already available in the code, as markers.
I don't think, I want to go through all my views and add custom markers.
Just my five cents.
Michael Kastner
replacing the open_id_authentication with another solved the rake problem.
script/plugin install git://github.com/senthilnambi/open-id.git
It may be an old version of open_id_authentication.
@John, I like the convenience of returning JavaScript directly. Running it through JSON adds another layer of complexity that I don't find necessary.
That said, I have little experience with heavy JavaScript applications, so in those cases it may be cleaner to only use JSON responses and keep the logic/behavior all in one place.
The argument reminds me of YAML vs Ruby code for config files. I generally prefer Ruby code for configuration because of the additional power it brings. It works really well as long as that power isn't abused.
What is your opinion on the idea that executing remote received javascript is a bad idea as well and that we should stick to passing xml/json and replace the content in a callback instead?