Re: [Hobo Users] Newbie Q: How to integrate new functionality?

46 views
Skip to first unread message

Bryan Larsen

unread,
Jan 5, 2013, 12:47:28 AM1/5/13
to hobo...@googlegroups.com
The standard way of adding a bunch of entries at once in Hobo is via
the input-many tag.

But that doesn't sound like what you want, since you want to use a
textarea. It may not be the best way, but how I'd probably do it
would be through a virtual attribute on your model. if you have a
BlackList that has_many :entries, you could do a "def batch_entries="
in your model that processes the textarea.
then:

<extend form for="BlackList">
<field-list: fields="foo, bar, batch_entries">
<batch-entries-view:>
<textarea name="&param_name_for_this" value=""/>

Bryan

On Fri, Jan 4, 2013 at 10:38 AM, Dan Lamet <danl...@gmail.com> wrote:
> I'm a RoR/ActiveScaffold veteran. I'm new to Hobo, however. I've just gone
> through the two-minute and Agility tutorials, and I've read through some of
> the other chapters, but I can't seem to figure out how to hook into the GUI
> properly.
>
> I have an app for which I'm keeping a black list. I'd like to retain the
> default Hobo ability to create a single record one at a time. But I also
> want to create a new page with a text area where I could paste dozens of
> lines of new black list entries for a batch add. I have the page built via
> an old style RoR action, but can't figure out how to create link on the Hobo
> page. I'd also be happy to inline the new functionality via Ajax. Any
> suggestions are welcomed.
>
> Thanks, Dan
>
> --
> 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/-/3pbCigKiPCkJ.
> 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.

Dan Lamet

unread,
Jan 5, 2013, 3:12:45 PM1/5/13
to hobo...@googlegroups.com
Bryan:

The "def batch_entries=" you suggest looks like what I want to do.  Can you tell me where the DRMYL you wrote would go?

Thanks,

Dan

Dan Lamet

unread,
Jan 5, 2013, 11:39:21 PM1/5/13
to hobo...@googlegroups.com
It looks like this code is supposed to go in the application.dryml.  With some massaging, it does recognize it.

<extend tag="form" for="Blacklist">
   <field-list: fields="identifier, bulk_add">
      <batch-entries-view:>
        <textarea name="&bulk_add_list" value=""/>
      </batch-entries-view:>
   </field-list:>
</extend>

I added an empty method in my blacklist.rb model called bulk_add.  This seems to invoke in the "New Blacklist" page.  (Is there any reason I should have expected that?)  And there is a label that reads, "Bulk add (Not Available)".  Was there possibly something really obvious that I might have missed?  (read newbie here)

Thanks again,

Dan

Bryan Larsen

unread,
Jan 6, 2013, 9:13:37 AM1/6/13
to hobo...@googlegroups.com
I forgot to mention that you'll have to add the new field to both your
permission functions and your attr_accessible.

cheers,
Bryan
> https://groups.google.com/d/msg/hobousers/-/wQOk6bV2Ng0J.

Dan Lamet

unread,
Jan 6, 2013, 3:46:45 PM1/6/13
to hobo...@googlegroups.com
No change.  My function is still unavailable.  Here's me adding to the permissions functions and attr_accessible.

class Blacklist < ActiveRecord::Base

  hobo_model # Don't put anything above this

  fields do
    identifier :string
    timestamps
  end
  attr_accessible :identifier, :bulk_add_list

...

  def bulk_add_permitted?
    true
  end

end

Bryan Larsen

unread,
Jan 6, 2013, 10:03:05 PM1/6/13
to hobo...@googlegroups.com
You've got some stuff named bulk_add_list and some bulk_add, it should
all have the same name. We're creating a "virtual attribute": to the
rest of the stack, it looks like a database column, but it isn't
actually a column in the database. So assuming that you have a
function

def bulk_add=(text)
(do something with text)
end

def bulk_add
""
end

On Sun, Jan 6, 2013 at 3:46 PM, Dan Lamet <danl...@gmail.com> wrote:
> No change. My function is still unavailable. Here's me adding to the
> permissions functions and attr_accessible.
>
> class Blacklist < ActiveRecord::Base
>
> hobo_model # Don't put anything above this
>
> fields do
> identifier :string
> timestamps
> end
> attr_accessible :identifier, :bulk_add_list
attr_accessible :identifier, :bulk_add

>
> ...
>
> def bulk_add_permitted?
> true
> end

You don't need this function. Just make sure that your
edit_permitted? returns true for the :bulk_add field.


>> > <extend tag="form" for="Blacklist">
>> > <field-list: fields="identifier, bulk_add">
>> > <batch-entries-view:>
>> > <textarea name="&bulk_add_list" value=""/>

"&bulk_add_list" means "return the value of the function or variable
named bulk_add_list". Since you do not have such a variable in your
view, this is going to cause problems.

What you want is name="blacklist[bulk_add]". If you inspect your
HTML, you'll see that's the format that Rails uses for form
parameters.

"param_name_for_this" is a view helper function in Hobo that will
return "blacklist[bulk_add]" when called in the above context. So
you want either name="blacklist[bulk_add]" or
name="&param_name_for_this". without the ampersand the string is a
literal, with it, the string is a function call.

Bryan

Dan Lamet

unread,
Jan 7, 2013, 12:58:10 PM1/7/13
to hobo...@googlegroups.com
Closer!  Now the page displays "bulk add" without the (not available), but there's still no text area to use. I've applied all your changes as best I can discern.  Here's my code to date:

class Blacklist < ActiveRecord::Base

  hobo_model # Don't put anything above this

  fields do
    identifier :string
    timestamps
  end
  attr_accessor :bulk_add
  attr_accessible :identifier

  ...

  def bulk_add=(text)
    ""
  end

  def bulk_add
    ""
  end

  ...

  def edit_permitted?
    true
  end

end

application.dryml
<extend tag="form" for="Blacklist">
   <field-list: fields="identifier, bulk_add">
      <batch-entries-view:>
        <textarea name="blacklist[bulk_add]" value=""/>
      </batch-entries-view:>
   </field-list:>
</extend>

class BlacklistsController < ApplicationController

  hobo_model_controller

  auto_actions :all

end

I must have misunderstood something.  I truly appreciate your patience, Bryan!

Thanks,

Dan

Bryan Larsen

unread,
Jan 7, 2013, 8:34:22 PM1/7/13
to hobo...@googlegroups.com
> <batch-entries-view:>

<bulk-add-view:>

> <textarea name="blacklist[bulk_add]" value=""/>
> </batch-entries-view:>

</bulk-add-view:>

cheers,
Bryan

Dan Lamet

unread,
Jan 9, 2013, 5:29:39 AM1/9/13
to hobo...@googlegroups.com
Getting so much closer!  Now I have the text area element showing up.  With a little cleanup and addition of an input element it, it looks pretty good.  I had to add an input element so that the form would submit.  But it does not seem to hit my method.  Here's my updated dryml.

<extend tag="form" for="Blacklist">
   <field-list: fields="identifier, bulk_add">
      <bulk-add-view:>
        <textarea name="blacklist[bulk_add]" cols="80" rows="40" autofocus="true"></textarea>
        <br/>
        <input type="submit" value="Add" />
      </bulk-add-view:>
   </field-list:>
</extend>


The bulk_add without a parameter gets called when the screen is constructed, but nothing gets called when the button is added.  Am I submitting my form wrong?  Without this input, there's no button at all.

Thanks again!

Dan
Reply all
Reply to author
Forward
0 new messages