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