Notes posted by newdark
RSS feedSort Integers
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
Sort From Greatest to Smallest
>> [1, 2, 3, 4].sort { |a, z| z <=> a } => [4, 3, 2, 1]
Alternitive to to add flash to respond with
This is a nice way to add flash if you don’t have a any logic that needs to go around your flash.
def destroy @current_user_session.destroy respond_with @current_user_session do |format| format.html {redirect_to login_path, notice: "You have been logged out"} end end
Found out you can't set the type to number
I am sure others have tried to do this but I thought I would add a not that tells ever one. You can’t use the type field in in rails 2.3. It is always set back to type => “text”
So if you are trying to set it to type => “number” it will not work. It always goes back to text. Sorry only way around this is to use a text_field_tag and set the type in that.
<%= text_field_tag :thing, type: "number" %>
Code above is the only way to set the type. in rails 3 you can just call number_field and it will work
Clarification with use of update_all
I would like to point out that if you are on rails 2.3.11 or lower you will not be able to run ledermann code.
Ledermann Code
user.messages.update_all(:read => true)
If you are running 2.3 or later it you will have to use James code
James Code
Message.update_all({:read => true}, {:id => user.messages})
thanks guys for all the code help
Recommendations
I would just use the path_to_image. I find that this is what works best. As it says above it can create problems.
Here is my code
Code example
def background_path(background) if background path_to_image background.file_name.normal else path_to_image "background_preview.jpg" end end def flavor_path(flavor) if flavor path_to_image flavor.file_name.normal else path_to_image("flavor_preview.jpg") end end
basic but gets the job done and it does not have problem with my pre built paths which are called image_path