Some interesting findings from web-dev land…
It’s simple but it’s useful!
To create an alphabet range array in PHP use this code:
1$range_array = range(’A',’Z');
Can anyone post the Ruby equivalent? Specifically alphabet chars.
This might be handy for anyone that’s using the Ruby on Rails will_paginate plugin/gem. It’s a helper that displays the result totals, current viewing range and page range based on an input Will Paginate collection array.
1234567891011def render_pagination_totals(will_paginate_collection=false)
if will_paginate_collection and !will_paginate_collection.total_entries.zero?
if will_paginate_collection.total_entries < (will_paginate_collection.current_page * will_paginate_collection.per_page)
end_of_range = will_paginate_collection.total_entries
else
end_of_range [...]
Don’t forget kids, error_messages_for seems only to like a symbol or a string of the instance variable name of your instantiated Active Record object (model). Not the object itself.
So this doesn’t work:
1<%= error_messages_for(@instance_variable_name) %>
Neither does this but then again it shouldn’t! (blogging for my own records):
1<%= error_messages_for(’active_record_model_class_name’) %>
This is what you want:
1<%= error_messages_for(:instance_variable_name) %>
A string [...]
I had a whole site that was .htaccess password protected using Apache authentication:
12AuthType Basic
etc etc
I wanted to allow public access to a sub directory. I had to Google it for quite a while and finally worked it out. I added this to the child directory .htaccess file:
1Satisfy any
The password prompt is now gone for that [...]
Managed to create a dynamic select menu with this code today. It includes a blank first value:
1<%= select("event", "search_type", EventType.find(:all).collect {|et| [et.name, et.id] }.sort, { :include_blank => ‘all’ }) %>
I had an integer field in a database table today (start age). It needed displaying as a select menu containing a number range within Active Scaffold. I thought for a while about creating a new model called age and creating a relationship, then I thought nah, that’s overkill. Anyway I figured out how to hard-code [...]
To create a Hash from a couple of Arrays you can do this in Ruby. I’m using a couple of Array ranges in this example.
OK the keys (strings):
1keys = (’1′..’99′).to_a
Now the values (integers):
1values = (1..99).to_a
Now the instantiation of the Hash object from the 2 arrays:
1hash = Hash[*keys.zip(values).flatten]
I know it’s basic but I have a whole stack of love for this function! To figure out which is the lowest of multiple values use min():
1$lowest = min($value_1, $value_2, $value_3, $value_4)
More info on the PHP site here
I installed the Hpricot gem today from the Hpricot GitHub homepage. I tried to parse some XML and got this error:
1uninitialized constant SearchController::Hpricot
Suddenly realised I should of required the library but the install documentation didn’t mention that. Managed to fix the issue with this line in my environment.rb
1config.gem "hpricot"
It was, (not 100% up on WAG2 yet) a W3C WAI accessibility recommendation to nest your form fields (inputs/selects etc) inside your label tags. So they were contained by the label much like you’d put an <img> tag inside an <a> tag to make it a link.
The Rails helpers don’t seem to have much [...]