Wednesday, June 25, 2014

LocomotiveCMS Multiple Select/Checkbox Many to Many

OK so I fumbled around with this for quite a while in LocomotiveCMS.  To get a public submission form to work with a set of checkboxes (and presumably with a multiple select) use a form element like this:


%input.resource-selection{type: :checkbox, value: '{{ resource._slug }}', name: 'content[interests][]', id: "{{ resource._slug }}" }><{{ resource.name }}

(That is inside of a liquid iterating loop, with a resource being a single entry in resources) The relationship on the model for public submissions is linked to the model that contains a list of options, via many-to-many so if you have a resources (in our case, requestable resources)

- messages:
    label: Messages
    type: many_to_many
    required: false
    unique: false
    localized: false
    class_name: messages
    ui_enabled: true
asd
and on the other side (messages, the field was called interests, as in "what I'm interested in")


- interests:
    label: Interests
    type: many_to_many
    hint: A description of the field for the editors
    required: false
    unique: false
    localized: false
    class_name: requestable_resources
    ui_enabled: true

Hope this helps someone.  Drop a note if you want me to try clarify something.

~Nic

Wednesday, August 28, 2013

Rails routing namespace removal, and avoiding catastrophe

So I am working on this project.  The project is one big application, with two sub applications.  One of the sub applications was axed in this context, but the other wasn't.  They had namespaces (say /first and /second)

it was requested to remove the namespace and put all of the controllers in the root namespace.

Panic ensued.

I came up with a quick solution, instead of re-writing a bunch of controllers, helpers JS and views:

Thankfully I had used path helpers in most cases, except javascript.  I went back, and put helpers in all of those places where I had been lazy, and used an actual path.  Then, when my routes file had

namespace :one do
  resources :things, :stuff
end

I changed it to (not inside any namespace)

scope module: 'one', as: 'one' do
  resources :things, :stuff
end

The module option sets the module prefix to be used in controllers (so I didn't have to change those), and the as option put the prefixes on the path helpers (so they'd still work even though it was all in root namespace).  

Upon further investigation, I found that the namespace route helper actually just uses scope like this


namespace :something do
  XYZ
end

converts to

scope module: :something, path: :something, as: :something do
  XYZ
end
So there.  If you ever need a wholesale change, you can drop the namespace helper in routes, and use scope to change the path without renaming a bunch of stuff. 

Hopefully this saves someone the headache I was looking at when the change was proposed.

~Nic

Sunday, April 28, 2013

Rails Single Table Inheritance With ActiveAdmin and Namespaces

So I stumbled with this for hours, working on a monkey patch for Inherited Resources, finally giving up. Basically, if you use STI with ActiveAdmin, don't use module namespaces. It breaks the shit out of inherited resources.. IH can't deal with the "Name::Class" ::'s, it just borks.. the monkey patch I was working on was to resolve the error when IH tries to use the model name as an instance variable like @Name::Class, which ruby is not interested in trying to do.


So, moral of the story: Don't use namespaced (with modules) STI models with AA, or IH.
~Nic

UPDATE: I was sent this from an anonymous commenter.  Excellent tip:

This actually works if you create a dummy class for your Namespaced model. For example do something like this: ActiveAdmin.register Parent::Child, as "MyClass". And then create a dummy model called MyClass as class MyClass < Parent::Child. This works.
UPDATE: I was sent this as well by another commenter:
This ugly shit works:
ActiveAdmin.register ::MyModule::Base, :as => 'MyModel'


without Dummy models

Monday, January 16, 2012

Holy shit I've got a RESTful connection to a non-rails app with Rails... only a billion goddamn overrides of ActiveResource every GOD DAMN time I use the thing:

This finder produces: http://...spex...net/service/rest/catalog?appId=xxxxxx&method=getVersion

EtilizeProduct.find(:catalog, :params => {:appId => 'xxxxxx', :method => 'getVersion'})
 
Reports: 200 OK 157 (199.0ms) (Version 3.0) XML

I had to override element_path in ActiveResource::Base to do this:

  class << self
    def element_path(id, prefix_options = {}, query_options = nil)
      prefix_options, query_options = split_options(prefix_options) if query_options.nil?
      "#{prefix(prefix_options)}/#{id}#{query_string(query_options)}"
    end
  end

#Idea from: http://www.quarkruby.com/2008/3/11/consume-non-rails-style-rest-apis
This is here in case I need to do this again.

~Nic

Wednesday, December 21, 2011

Klobuchar & Franken: Pull your heads out of your asses.

SOPA isn't part of a war on piracy, it's part of the civilization-old push against the free exchange of information.

Don't think for one fucking second that because the internet exists as it does now -- as a place where you can say anything you want, blog about whatever, edit Wikipedia -- that it will continue to exist that way in the future.

I will quote Leary out of context:
"Throughout human history, as our species has faced the frightening, terrorizing fact that we do not know who we are, or where we are going in this ocean of chaos, it has been the authorities — the political, the religious, the educational authorities — who attempted to comfort us by giving us order, rules, regulations, informing — forming in our minds — their view of reality. To think for yourself you must question authority and learn how to put yourself in a state of vulnerable open-mindedness, chaotic, confused vulnerability to inform yourself."

The SOPA (and Protect IP) legislation, (and those who are also opposed to net neutrality) are another incarnation of that authority that wishes to crush the human spirit "for its own good". 

This anti-human legislation has support from people on BOTH sides of the aisle, including Klobuchar and Franken.  They can both go fuck themselves.

This is serious shit.  Capitol Hill Switchboard: 202-224-3121

~Nic

Sunday, December 4, 2011

Steeeeeeeeeeeeeerike one

I hate love it when people use strike-through.  It was cool the first thousand times conveys originality.  Go fuck yourself Have a nice day.

(This isn't directed at anyone in particular, so if you're offended you're an idiot I'm sorry.

~Nic

Friday, November 25, 2011

May the greed be with you

And also with you.

Being that today is black Friday, and I've been reading AdBusters for the last decade, and there's an occupy movement happening, I decided to think on greed a bit today.  I am a fucking concern troll.  That said, let's see the definition
excessive or rapacious desire, especially for wealth or possessions.
Shit.  That's not very helpful.  How about excessive
going beyond the usual, necessary, or proper limit or degree; characterized by excess: excessive charges; excessive criticism.
 Well piss.  It seems that we're going to end up on a loop of looking up subjective labels.  And... I'll be damned: that's the problem.  There's nothing inherently wrong/bad with/about greed.  There's not.  The real problem is with propaganda.  If I say:
I want to squeeze every ounce of money out of my employees, working them to death.  To do this I will lobby against the minimum wage under the banner of worker freedom.  I will work to convince people that the 40 hour work week is oppressive -- they could work more if only I didn't have to pay them more -- and should be abolished.  I will forgo basic safety precautions, as they are expensive.. and everyone knows they shouldn't put a stroller on an escalator, why do I need to spend the $50 to put a sign there anyhow?
 and call it anything other than greed, I am lying.  It is true that the definition is subjective - that excessive is "in the eye of the beholder".    But this subjectivity is being used against all of us.  The "Reasonable Person" has been killed (by Mammon himself, no doubt), and we've let everyone get away with it.  I think it is specifically because "greed is not inherently bad" that we forget that it is also not inherently good.  Because of this, we find ourselves allowing our conservative friends/enemies/whatevers to escape us when we don't say:
...perhaps Laffer was originally right, but how is cutting taxes on the rich while maintaining tax levels, or increasing them on the middle class and poor not an example of wealthy greed?
Right.  That's fucking right.  It's the same answer I give to "well, if you don't believe in God, what reason do you have to live"?  I say "any reason to live has no bearing on the existence of God".

But anyhow, we've got to stop allowing people to say that "big corporations are not greedy, they're just doing what they do", and the like.  While greed is not inherently bad/evil, neither is infanticide (it sounds pretty fucking lame that I would say that, but ontology is pretty brutal).  I think we can all agree that infanticide is unacceptable, can't we agree that at least SOME greed is also unacceptable?

~Nic

Monday, November 14, 2011

OCI8 with Phusion Passenger/Rails 3.1 on Freebsd 8 ** UPDATED

This has been one of the most trying things I've done..  My employer uses a backend database of Oracle 9i, or the like.  I have to connect to it with Rails to simplify some queries, using oci8. 

Ruby 1.9.2 also.

Install the freebsd linux-oracle-instantclient-* ports
follow directions here: http://ruby-oci8.rubyforge.org/en/InstallForFullClient.html
(You will have to install both oracle ports)

Punch something that won't break your hand, but will be hard enough to relieve some anger

Use gems, NOT the ports collection for the gems..

gem install ruby-oci8 (Using the freebsd port fucks everything up)
gem install activerecord-oracle_enhanced-adapter

You will have to modify  /usr/local/lib/ruby/site_ruby/oci8.rb to make line 38 know where your .so file is.  replace site_ruby with your ruby install path.  I use site_ruby because of rvm (Another goddamn hassle to set up)

This got me up and running, but I am not sure if these steps are in order, or if I did anything else.  This was a fucking hassle and I  wouldn't recommend doing it.. but if you have to, and you get stuck, post a comment and I'll see if I can't help you figure out your problem

~Nic

ETA:

A ruby wrapper to set this bullshit is necessary as well:

#!/bin/sh
export LD_LIBRARY_PATH=/usr/local/oracle8-client/lib
export TNS_ADMIN=/usr/local/oracle8-client/network/admin
export NLS_LANG=AMERICAN_AMERICA.UTF8
export ORACLE_HOME=/usr/local/oracle8-client
exec "/usr/local/bin/ruby" "$@"

ETA2:

This only works on fucking i386.  If you have to use OCI8 on FreeBSD, it's only going to work on i386.  I tried and tried, and no x64.

Tuesday, November 8, 2011

God hates cigarettes?

"I don't really care what people do in their private lives," said 62-year-old communications consultant George Werl of Minneapolis. But he said marriage should be limited to heterosexual couples because it was designed to protect the children of those unions. (via)

What he means to say is:
"I don't really care what people do in their private lives.  I really care what people do in their private lives".  It's a Rick James moment.

This amendment vote is a year away.  We must all fight it.  Fuck the spin, it's homophobic, bigoted and simple minded.  Marriage is a dying arbitrary patriarchal institution anyhow, not to mention the SIBS study has all but proven that biological relationship between parents and children has no impact positive or negative on the child's "success" in life (but it's OK to use a child to force a mother or father into "calming down"/"growing up")

These are bogus issues designed to pit us against each other and ignore the reality that we're all being screwed ... by the 1%  (Thanks adbusters for making that so succinct).  If you REALLY FUCKING DON'T CARE what people do in their private lives, [then] SHUT THE FUCK UP.

Amen brother.

~Nic

**edit: than? Idiot.

Wednesday, November 2, 2011

Let there be plight

I am severely troubled by how the fox spin machine is portraying the occupy movement (but not surprised).  It's something I am afraid has been picking up steam for a while: "college education is unnecessary" (I know, this isn't news).  Of course, these people don't believe that's true for anyone in their families..

I remember something that I heard on public radio years ago that solidified my stance of pro-education for everyone (regardless of costs).. some jacknut Eichten had on his program said "Now Gary, what do I care if my car mechanic knows where Iraq is".  I got a great insight into the bourgeoisie/proletariat divide in that moment, and I drew an instant parallel to the dark ages.  This seems to me to be the definition of serfdom (After enlightenment, but before access).

I want my car mechanic to know whatever in the fuck he/she wants to know, and to be able to critically think as to properly question their government, make wise decisions on health care, child raising, etc.  They're trying to put out our sacred flame of the enlightenment.  Every bit of money taken out of education, every extra pupil in a classroom, every closed Adult Basic Education program -- they're all one more depressant on that flame.

Also, too: fuck Locke.

~Nic

**Edit I said fuck Kant: I was thinking Locke but wrote Kant.  I've got no beef with Kant's a priori (although I used to hate the concept), my beef is with Locke's private property nonsense.

Monday, October 24, 2011

Fuck city living

A drive by shooting with over 30 rounds fired from 3 different firearms at 1am (All fired within about 5 seconds) NEXT DOOR?  A desk pig that basically mocked me for calling the next day with worry about that, two cars broken into down the block, and the dude who was trying to rob my renters house?  Subwoofers?  Why do I live in the city?

Whatever weapons were used in this fucking drive-by, they were serious shit.. The walls of that home are plaster, and apparently there were rounds that made it clear through the WHOLE FUCKING HOUSE.  The fridge, which has the outside wall, and an inside wall between it and the direction of fire, has bullets lodged into the side of it.  Apparently a few strays hit the neighboring house (on the other side).  This fuckhole pig is annoyed with my concern?

I can't properly show the vibe I got from him, but here's a little excerpt:
Cop: "We don't have any information about any of those situations"
Me: "uhhhhhhh ok?  Are you a cop?"
Cop: "uhhhhh yeah I am a cop"
Me: "How am I supposed to feel about this?  There was a fucking war going on outside of my home last night.  You can't give me any information about any of it.  What am I supposed to do?  Tell me.  Give me some advice here."
Cop: "Lock your doors and windows"
Me: "Helpful.  am I going to have to keep a loaded firearm under my pillow?"
Cop: "It wouldn't be a bad idea.  Get training and a handgun."
Me: "Reassuring."

6 Months ago all I had to worry about was obnoxious subwoofers.  Now I find myself plowing my gf off the bed to the floor at 1am because HOLY FUCK WE'RE UNDER ATTACK!

At least he'll see what he can do to up the patrol time for my area.

~Nic

Friday, October 14, 2011

STNG weighs in on gender issues

Watching Star Trek the Next Generation on 'flix is probably my best time waster ever.  Anyhow, in "The Outcast" was this monolog from a person who was part of a "sexless" race, and she had feelings of being a woman her entire life, which is apparently forbidden on whatever-the-fuck planet she's from (Cut/Pasted from IMDB):

I am female. I was born that way. I have had those feelings, those longings, all of my life. It is not unnatural. I am not sick because I feel this way. I do not need to be helped. I do not need to be cured. What I need, and what all of those who are like me need, is your understanding. And your compassion. We have not injured you in any way. And yet we are scorned and attacked. And all because we are different. What we do is no different from what you do. We talk, and laugh. We complain about work. And we wonder about growing old. We talk about our families, and we worry about the future. And we cry with each other when things seem hopeless. All of the loving things that you do with each other, that is what we do. And for that, we are called misfits, and deviants, and criminals. What right do you have to punish us? What right do you have to change us? What makes you think you can dictate how people love each other?


The Judges Response: I congratulate you, Soren. Your decision to admit your perversion makes it much more likely that we can help you.

..Riker: "Did it occur to you that she might want to be like this?"
 It's a beautiful episode, one among many.

 ~Nic

Wednesday, October 12, 2011

Fuck you, homosexual!

The title is in reference to gingergate, and is intended to convey irony.

(via) "One school district bars teachers from taking a position on homosexuality."

I don't understand this concept of "neutrality" with regard to homosexuality... How do you remain neutral on a fact?  Let me hyperbolize:

Student: "Hi, I'm Billy, I am gay."
Teacher: "I can not confirm or deny the existence of homosexuality."
Student: "How about if I just say I'm straight?"
Teacher: "I CAN confirm the existence of heterosexuality."
Student: "Doesn't the acknowledgement of one infer the existence of the other, exempli gratia: darkness implies light?"
Teacher: "Why do people think I earn too much?"

Am I misinterpreting their idea of neutrality?  Perhaps I am taking them literally what they are asking for.  To remain neutral on a characteristic is to not have an opinion on its existence (See: agnostic(loosely)).  Though what's implied (and what they really mean) is that teachers ought to remain neutral on the "good" or "bad/evil" of such a characteristic, however this is not possible..  Just as some people might think Gingers are evil and should all be killed(I went there), which is highly irrational since hair color (along with skin color, sex, etc, etc) are characteristics over which the holder has no control, homosexuality fits the same bill, and is therefore transcendent of any arbitrary judgement of goodness.  The only choice a teacher has is to take a position something like:

"The fact in the matter is that this particular (or that particular) child is homosexual(or hetrosexual).  My purpose is to protect my students from hatred in any form, and therefore hatred, and/or bullying directed at any child is unacceptable.  I will not remain neutral when a child is harassed, and it follows that I will not remain neutral when a homosexual child is harassed, the harasser will be punished."

I remain neutral [and] on the moon.

These fucking haters are so GOD DAMN stupid, and nicotine withdrawal makes me that much more fucking angry about it.  Stop being a fucking hater. 

~Nic

**edit: The MIA video was supposed to be interpreted far differently than it ended up being, and is used to progress a very long and old "ginger-phobia" tradition in UK, and other parts of Europe.  This (not the video, the UK/euro issue) was an ace card I had in my back pocket during Gingergate, and didn't need to use.

Wednesday, October 5, 2011

Rails 3 - unit testing validators with check validate reflection method

I don't know if this is to best practices or not (and I really don't give a shit -- this works great). Here's the idea:

model:

class Submission < ActiveRecord::Base
  validates_presence_of     :title 
  validates_presence_of     :first_name
  <snip>
end


I load some data in with a fixture to make the model valid.... blah blah

unit test:

require 'test_helper'

class SubmissionTest < ActiveSupport::TestCase
  def setup
    @one = submissions(:one)
  end
  test "empty title invalidates" do
    assert !check_validate(@one,"title")
  end
  
  test "empty first name invalidates" do
    assert !check_validate(@one,"first_name")
  end
 .....


Now the check_validate method, and the quick check method:


def check_validate(object,field)
    #Make sure object is valid
      assert_object_valid(object)
    #set old to objects value 
      old = object.send(field.to_sym)
    #send setter to object along with nil to blank it
      object.send("#{field}=".to_sym, nil)
    #set return value to boolean of valid? on object
      return_value = object.valid?
    #send setter to object for field with old value
      object.send("#{field}=".to_sym, old)
    #Make sure we leave the object valid when we're done
      assert_object_valid(object)
    #return the value
      return return_value
  end
    
  def assert_object_valid(object)
    assert object.valid?, "test entered with invalid object"
  end



It works great.. nice and DRY, this way I don't have to blank them all out, and put them all back.. ruby's reflection is a billion light years beyond any I've used for anything else ever. (Java? what?) I plan on modifying the check_validate to simplify other checks as well, and create my own library of test for common tasks. Maybe it already exists? I looked, and didn't find one.

~Nic

Sunday, October 2, 2011

Liberal propaganda.

**Edit: I spelled propaganda wrong. Again.

Wheeee I've been saving that one. So I spend the last 2 days, about 16 hours working on my sweet new shed with my father. I've gotten him into reading some blogs, and we discussed at length a few repeating patterns we've both noticed (and are by no means immune to):

1. There is a liberal dogma.
2. I agree with a lot of it.
3. We both have a hard time with any dogma.

1: We all know what the liberal dogmatic stances are on everything from global warming, to birth control, to affirmative action, to every other goddamn thing under the sun. While I find myself in agreement with most all of the dogmatic stances I, become thoroughly annoyed when someone chimes in with a completely rational argument against one of them, and the chimer-inner is dismissed as a troll of some sort, and the argument is not explored. I haven't yet found myself labeled a troll on a blog (I don't comment much anywhere), but I can positively conclude that I would be labelled a troll should I chime in.

Even when I am in complete agreement with a stance, political position/posture, or the like my brain immediately begins the devil's advocate program (v 30.3 It needs work, but it's done well for me). I don't do this to necessarily be argumentative, but to be exploratory. I believe this is a byproduct of the general troubleshooting skills I have honed over the whole of my life. I must consider as many alternatives as I possibly can, and should I find a logical conflict, I must do everything I possibly can to correct it. Logical inconsistencies infuriate me, although I have to live with a few (for example, the only logical conclusion I can draw from some of my new-found non-religious frameworks is that eating meat is unacceptable (pain/suffering/killing/etc of sentient beings), however, I continue to eat meat.. and probably will until I can no longer withstand the mental pressure to do otherwise).

2: Yup. Most.

3: Following dogma means acceptance without regard for the truth (should the actual truth be part of the dogma is beside the point). I have, since I can remember, absolutely refused to believe anything that I couldn't conclude with my own thought (when I eventually find the time to think about it. The queue is long). This is why I have no problem dismissing arbitrary authority -- which has caused me a lot of easily avoidable problems -- and making that dismissal quite outward.

I have concluded that the label of troll, in some circumstances (I can't give a %) is intellectual laziness. It's simply name calling with the end of dismissal of an uncomfortable question (in the cases where it's lazy).

While the comfort of dogma may have great appeal to some (and dogma is politically agnostic), I will not accept what I am told. Regardless of the authority of the preacher.

To be cliche:





~Nic

Tuesday, September 27, 2011

I'm about to slap someone..

For the last goddamn week some fucking asshat has been parking across the street and down 2 or so houses. They pull up and about 10 people pour out of this vehicle and they proceed to test the nerves of the surrounding 2-3 blocks with wall-shaking bass. This, of course, annoys me endlessly. The passing vehicles with obnoxiously loud bass I've managed to deal with fairly well mentally.. as long as I know it will go away I can take a few deep breaths and forget it (When I first moved to Minneapolis in 1998 I thought I was going to die of panic attacks). But this lingering shit destroys my spirit.

SO -- Calling the cops is useless, they're too busy pulling people over for trivial nonsense (esp. if they're a minority)..

So what's a ginger to do?

I think I am going to buy a few Air Horns. I am going to rig something up so I can set it and leave with the goddamn thing blaring away. Leave it on the doorstep with a nice note that says "TURN YOUR FUCKING MUSIC DOWN YOU ASSHAT".

What will I really do? Nothing. I'll sit and stew in my basement while my nerves drive me to fantasize about some form of payback for my torture. ..Oh, and continue to browse for homes in first-third ring suburbs.. and wish I made more money.

~Nic

Monday, September 26, 2011

We have a problem

We have a fucking problem here:

A small town in Alabama is offering non-violent offenders the choice between doing prison time and paying a fine, or working their sentence off by going to church every week.

From TPM

~Nic

Rails 3 - Check if any possibilities exist before validation

In this work project I have a few models: contest model, submission model, and subject model. Subject is a table that belongs to contest, AND subject. Some contests don't have subjects, but if they do, I need to have the user select one. These few snips of code worked well for that situation:

class Submission < ActiveRecord::Base
  
  #Set up how the model works
  belongs_to                :contest
  belongs_to                :subject

  #Validate the field we're talking about in this post:
  validates_presence_of     :subject_id, 
                              :on => :create,
                              :if => :needs_subject?


.. And later I defined needs_subject? as follows:


  def needs_subject?
    if self.contest.subjects.any?
      return true
    else
      return false
    end
    
  end
end #End the model.


So this allowed me to only check if there's a subject if there SHOULD BE a subject.

Hope this helps someone.

~Nic

Monday, August 29, 2011

Probability of god making an earthquake and hurricane?

0.

Tell yourself whatever you want. For the record, the probability of a hurricane arising within 1 day, 1 week or 1 year after any arbitrary point (in this case, after an earthquake) is exactly the same, given seasonal adjustments. When events are close together, we notice. Had these two events been a year apart it would be a different story for the christnuts.

Back to homework.

~Nic

Thursday, August 25, 2011

LifeNet Autonomous net

Apparently my idea does exist, though it is in a quite broken-down and seemingly abandoned way. I would think that the source for that project could be branched and modified to do what I had proposed earlier. Find it here: LifeNet

~Nic