On Thu, Jan 26, 2012 at 10:20 AM, JezC <[email protected]> wrote:
> Hi, I've been working on lifecycles... I can transition between states
> very nicely. I'm wanting to have one action that edits. I've got an
> index page that shows the transition buttons, and I can step the model
> between the states, redirecting to the index page.
>
> app/models/my_model.rb
> ...
>  lifecycle do
>    state :saved, :default => true
>    state :submitted
>    state :editing
>    state :deleted
>
>    transition :delete, {:saved => :deleted}, :available_to => :owner
>    transition :submit, {:saved => :submitted},  :available_to
> => :owner
>    transition :save, {:editing => :saved}, :available_to => :owner
>    transition :alter, {:saved => :editing}, :available_to => :owner
>  end
> ...
> app/controllers/my_model.rb
> ...
>  def do_submit
>    do_transition_action :submit do
>      redirect_to my_models_path
>    end
>  end
>
>  def do_alter
>    do_transition_action :alter do
>      redirect_to edit_my_model_path
>    end
>  end
> ...
>
> And that's where I get lost and confused. I want to update the /
> my_model/12/edit page. So I think I need to alter the <edit-page> in
> app/views/my_models/edit.dryml but I need to alter just the submission
> buttons in the form, don't I? I can see how to replace the entire
> form, I think (<replace-content-body>...</replace-content-body>), but
> I believe that what I need to do is to replace the final Submit button
> in the form with my two transition buttons (I can "save" or "submit"
> an object in the "editing" state). Replacing the whole form wouldn't
> be DRY enough for Hobo style coding ;)


Here's how to do what you asked.   That's not what you want, but it's
what you asked for:  :)

<edit-page>
  <form:>
    <submit: replace>
       <transition-buttons/>
    </submit:>
  </form:>
</edit-page>

What you want to do.

1) add params to your save transition.    Hobo automatically makes a
page with the form for lifecycle actions

2) link to it from your show-page (or wherever)

    <a action="save">Edit Foo</a>

3) turn off the non-lifecycle edit link in your controller.

  auto_actions :all, :except => [:edit]

If you're on the latest version (gem "hobo", :git =>
"git://github.com/tablatom/hobo", :branch => "1-3-stable") in your
Gemfile, you can do:

<show-page>
  <after-field-list:>
    <transition-button transition="alter"/>
    <transition-link transition="save">Edit Foo</transition-link>
    <transition-button transition="delete"/>
    <transition-button transition="submit"/>
  </after-field-list:>
</show-page>

Bryan

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to