All posts by a.philippi

Install libxml-ruby gem on FreeBSB 9

I want to install libxml-ruby version 1.1.4.

I have libiconv and iconv installed, but I get the following errors:

extconf failure: need libiconv.

Install the libiconv or try passing one of the following options
to extconf.rb:

--with-iconv-dir=/path/to/iconv
--with-iconv-lib=/path/to/iconv/lib
--with-iconv-include=/path/to/iconv/include

Solution: “teach” the gem the path to your iconv lib like this:

gem i libxml-ruby -v 1.1.4 -- --with-iconv-lib=/usr/local/lib

restart mysql master/slave synchronisation after an invalid SQL query

you may encounter stuff like this:

a SQL clause that returns different error codes on master and slave, for instance if you use different versions of mysql:

[ERROR] Slave SQL: Query caused different errors on master and slave. Error on master: ... Error on slave:

To restart synchronisation simply skip that SQL clause this way:

SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;

Of course the 1 may be replaced with “n” if you want to skip multiple SQL clauses.

append tt_content date for each content element in typo3

typo3 - edit tt_content date field

sometimes it’s useful to append a custom field to each content element in typo3, in my case it was the tt_content date – see the attached screenshot

I decided to attach the date to every tt_content-Element with a certain Layout – the second in the list.

It’s pretty simple:


temp.mainTemplate = TEMPLATE
temp.mainTemplate {
template =< plugin.tx_automaketemplate_pi1 ...... workOnSubpart = DOCUMENT_BODY subparts.main_content < styles.content.get subparts.main_content.select.where = colPos = 1 subparts.main_content.renderObj.text{ 1000=TEXT 1000.value= begin some wrapping code ... 1010=TEXT 1010.field = date 1010.strftime = %A, %e. %B %Y 1020=TEXT 1020.value= end some wrapping code ... } ..... } .... page = PAGE page.typeNum = 0 ... page.10 < temp.mainTemplate ....

sqlite 3 gem on freebsd

have a rails app and need sqlite3 gem compiled on your freebsd environment?

gem install sqlite3 -- --with-sqlite3-include=/usr/local/include --with-sqlite3-lib=/usr/local/lib

and if you need to use bundler for a rails 3 app, you should do


bundle config build.sqlite3 --with-sqlite3-include=/usr/local/include --with-sqlite3-lib=/usr/local/lib

bundle install

simple but effective usecase – attr_accessible in rails 3.1

We have the following situation:

A rails 3.1 – project we are working on

We have a model called recipe, we want to allow access for mass assignment for a limited set of attributes for “normal users”, and for all attributes for the users with the “admin” role.

This can be done as follows:

class Recipe < ActiveRecord::Base attr_accessible :attr1, :attr2, :attr3 attr_accessible :attr1, :attr2, :attr3, :attr4, :attr5, :as => :admin
.....

This way attr4 and attr 5 will be accessible using mass-assignment only by the admin role….

But in our case we want ALL attributes to be accessible to the admin role, we do not want to write a long and complete list of all attributes. This would save us a lot of work in case we decide to create new attributes using migrations for example.

So we found out we can use the method attribute_names and the splat operator(*) to dynamically create a list of all attribute of that class which can be passed as parameters to the attr_accessible call.

class Recipe < ActiveRecord::Base attr_accessible :attr1, :attr2, :attr3 attr_accessible *attribute_names, :as => :admin
.....

And it works just fine πŸ™‚

Note: if you want to include also all has_many, has_one, has_and_belongs_to_many relations/associations you can use something like this

attr_accessible *(attribute_names + reflect_on_all_associations.collect(&:name)), :as => :admin