Category Archives: Why do I do this to myself

Saying goodbye to Rails

I give up.

Everywhere I look suggests that what I have should be enough for this to work. But it isn’t.

And since this is a fundamental feature of the project, and what with the still patchy cross-browser performance of JQuery auto-select, it’s time to abandon Rails and look for another framework.

So, I will be taking a pause while I get Django up and running. Rails is no more.

Wot, no controller?

While considering where I was going wrong with my Rails project, I figured that since I had the model and the views covered, I ought to give some consideration to the controller.

Then it occurred to me that the reason why no form elements were being shown on the new commission page was because I hadn’t created any! The standard scaffold controller action can be a little basic with show and edit completely blank.

But the ‘new’ controller does create an object and this is where the form elements com from. And in earlier tests, I had seen that I could use a build method to create the nested attributes. This should be easy.

Surely all my controller needs is:

 def new
   @commission =

So why does that give me the following error:

undefined method `build_activity' for #<Commission:0x007f9e10be7020> Did you mean? build_commission_type

I can change the controller as suggested,

 def new
   @commission =

And although the page loads, there are no form elements displayed. It’s wrong anyway, so I’m not bothered about that.

Perhaps the problem boils down to using a word that that plurals with ‘ies’ and that needs to be reflected in the appropriate places: sometimes singular sometimes, plural, other times pluralised. Sometimes errors, sometimes nothing.

This is the Rails way: everything’s a battle. Every step of the way.

3 sources, all slightly different, none work

Now on the case with (yes, I know, Rails 4, probably isn’t supported in 5) and mentions more possibilities that probably aren’t relevant, but don’t work anyway.

I mention it here because if (I’m not confident enough to say when) I get this working I will be needing to auto-populate some fields (am I mad!) and there might be value in the comments.

It’s another one of those times when it’s clear that I’m doing something wrong (other than actually attempting to do this) but I have no idea what and very little indication of where to start looking. For all the times that development can accelerate with Rails, there are these occasions when it grinds to a halt and you’re never actually sure how it got fixed.

It couldn’t last

It didn’t take long for my development with polymorphic associations and forms to founder.

The very next stage after my last post on the matter, in fact. And I now have a second reference source that, while providing an additional nudge, isn’t enough to see me through the current block.

To be able to nest the activity section on the commission form, we need to tell the commission model to accept activity fields,

accepts_nested_attributes_for :activities

(I originally hd this as :activity after the model name, but it gave a missing model error; then my initial hunch was probably that accepts_nested_attributes_for was no longer supported in Rails 5; these things rarely work for very long).

A quick search on the topic of continued rails support for accepts_nested_attributes_for took me to, which is a nicely written page which only backs up my original source. Curiously, however, it includes a step that shows successful data posts before they’ve been added to the form.

Then we simply add the following to the commission form,

 <% f.fields_for :activities do |act| %>
 Title: <%= act.text_field :title %>
 Details: %= act.textarea :details %>
Number of slots: <%= act.number_field :number_of_slots %>
 Min slot separation: <%= act.number_field :min_slot_separation %>
 <% end %>

Then nothing. No errors, log messages or anything. Nothing. Nothing ever works the way it’s described and a heavy price is to be paid for every advance.