Editable child models

34 views
Skip to first unread message

pmo...@concord.org

unread,
Jan 22, 2013, 10:17:11 AM1/22/13
to hobo...@googlegroups.com
We have a model in our site for Multiple Choice questions, which has children helpfully if tongue-stumblingly called MultipleChoiceChoices. They're a pretty simple model, just a name (text field) and a boolean indicating if they're the correct answer.

I should probably point out here that we're using Hobo 1.3.

Currently, MultipleChoiceChoices aren't editable; if a user doesn't like one, they need to delete it and create a new one. We're trying to make them editable. I tried at first to do this by adding an edit-in-place field for the name in the card, so on the MultipleChoice show page, the choices would each be editable in place. 

I tried several varieties of this, but none of them worked:

<def tag="card" for="MultipleChoiceChoice">
  <card class="multiple-choice-choice" param="default" merge>
    <div class="#{this.correct ? 'correct' : 'incorrect'}">
      <header: param>
        <h4 param="heading"><editor ><name/></editor></h4>
        <div param="actions">
          <delete-button label="X" param/>
        </div>
      </header:>
    </div>
  </card>
</def>

Frustrated with this, I went on to just trying to make an edit link in the card:

<def tag="card" for="MultipleChoiceChoice">
  <card class="multiple-choice-choice" param="default" merge>
    <div class="#{this.correct ? 'correct' : 'incorrect'}">
      <header: param>
        <h4 param="heading"><name/></h4>
        <div param="actions">
          <a action="edit" param="edit-link">Edit</a>
          <delete-button label="X" param/>
        </div>
      </header:>
    </div>
  </card>
</def>

...but while this puts the text "Edit" on the page, I haven't been able to get an actual link. (This is one of the attempts I've made, by no means the only one.)

Can anyone push me towards the correct DRYML syntax for either an edit-in-place name attribute, or a working edit link? Thanks.

pjm

Bryan Larsen

unread,
Jan 22, 2013, 10:19:15 AM1/22/13
to hobo...@googlegroups.com
Check your permissions on both the child model and the parent model.
If Hobo is refusing to display a link or to put an editor on a field,
it's likely because the edit permissions on your models are not set to
allow it.

Bryan
> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/hobousers/-/jgVoLBP5JegJ.
> To post to this group, send email to hobo...@googlegroups.com.
> To unsubscribe from this group, send email to
> hobousers+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/hobousers?hl=en.

pmo...@concord.org

unread,
Jan 22, 2013, 10:32:21 AM1/22/13
to hobo...@googlegroups.com
Thanks for the quick reply, Bryan!


On Tuesday, January 22, 2013 10:19:15 AM UTC-5, Bryan Larsen wrote:
Check your permissions on both the child model and the parent model.
If Hobo is refusing to display a link or to put an editor on a field,
it's likely because the edit permissions on your models are not set to
allow it.

Boy, it would be cool if that was all it was; I hadn't thought of that, because I don't understand permissions all that well. Is that edit_permitted?

  def edit_permitted?(attribute)
    return true if acting_user.administrator?
    return self.is_owner?(acting_user)
  end

I'm both an administrator and the owner of these models. This block is in a module included by both parent and child models.

pjm

pmo...@concord.org

unread,
Jan 22, 2013, 10:36:31 AM1/22/13
to hobo...@googlegroups.com
I should probably also provide the controller code.

This is the parent:

class MultipleChoiceSequencesController < ApplicationController

  hobo_model_controller

  auto_actions :all, :except => :index
  polymorphic_auto_actions_for :page, [ :index, :new, :create ]

end

The :page model is this model's parent. This is the choice controller itself:

class MultipleChoiceChoicesController < ApplicationController

  hobo_model_controller

  auto_actions :write_only
  auto_actions_for :multiple_choice_sequence, :create

  # The default method created by
  # auto_actions_for  was redirecting to "/"
  # (probably an edge-case bug for mutliple child associations)
  #
  def create_for_multiple_choice_sequence
    hobo_create do
      page_path = params["page_path"]
      redirect_to  page_path if page_path && valid?
    end
  end
end

I tried changing the auto_actions_for :multiple_choice_sequence here, but making it [:create, :update] didn't help (it actually produced errors).

pmo...@concord.org

unread,
Jan 22, 2013, 2:07:39 PM1/22/13
to hobo...@googlegroups.com
We got this sorted out:


On Tuesday, January 22, 2013 10:36:31 AM UTC-5, pmo...@concord.org wrote:
class MultipleChoiceChoicesController < ApplicationController

  hobo_model_controller

  auto_actions :write_only
  auto_actions_for :multiple_choice_sequence, :create

end

A look at hobo_routes.rb showed that the "edit" route didn't exist, although "update" did. 

Changing `auto_actions :write_only' into `auto_actions :all' created the route, and then the edit-link tag worked.

Thanks,

pjm
Reply all
Reply to author
Forward
0 new messages