How to pass variable to a widget?

64 views
Skip to first unread message

Mike Pence

unread,
Dec 11, 2012, 2:13:44 PM12/11/12
to cells-an...@googlegroups.com
What a newb question, I know, but how do I pass a collection of items in a variable to a widget in a render widget call?

Nick Sutterer

unread,
Dec 11, 2012, 4:36:07 PM12/11/12
to cells-an...@googlegroups.com
Either

render_widget :name, :whatever => "yay!"

Or, if you need the information in both render- and trigger-state:

has_widgets do |root|
root << widget(:name, :whatever => ...)

;-)

Mike Pence

unread,
Dec 11, 2012, 5:28:03 PM12/11/12
to cells-an...@googlegroups.com
render_widget(:local_projects, :display, :projects => @local_projects) worked.

Nick Sutterer

unread,
Dec 13, 2012, 7:37:38 AM12/13/12
to cells-an...@googlegroups.com
Be advised that the options you're passing to the widget are only
available when rendering the widget in the page ("render state") - if
you need to process this data when an event is triggered ("trigger
state") the options hash is no longer present as there's a request
inbetween. Use the #has_widgets trick I showed you. What are you
building, bro?

Mike Pence

unread,
Dec 13, 2012, 11:11:30 AM12/13/12
to cells-an...@googlegroups.com
I have been building crowdfunding sites (http://haydukelabs.com), and we're completely re-doing the presentation layer to support Twitter bootstrap, among other things. So, I decided to break the entire UI up into widgets, to have an entirely component-oriented rails app, while we are at it. I am plenty sick of monolithic views and I really want to feel good about the modularity of the UI, and be able to get server-side events and stuff for free with Apotomo.

BTW, have you seen Vaadin? http://demo.vaadin.com/sampler

Best,
Mike

Mike Pence

unread,
Dec 16, 2012, 1:46:14 PM12/16/12
to cells-an...@googlegroups.com
Ok, so you add the variable by symbol and use an instance variable, and it shows up in the options hash for every call. Works for me.

Mike Pence

unread,
Dec 16, 2012, 5:25:03 PM12/16/12
to cells-an...@googlegroups.com
Guess I am still confused. When you have a widget within another widget, you can't (or shouldn't) do the magic naming in the has_widgets block, because you don't want to tightly bind a widget in the tree of rendered widgets to a top-level domain name.

So, you would think, this would work:


In that example, the options hash is empty when rendering the :project_1 widget.

Nick Sutterer

unread,
Dec 17, 2012, 5:19:06 AM12/17/12
to cells-an...@googlegroups.com
Where does

@projects = options[:projects]

come from? Can you show me the top-level #render_widget call in the
controller view?

Ahmad Musaffa

unread,
Aug 8, 2014, 6:08:36 PM8/8/14
to cells-an...@googlegroups.com
I tried with you suggestion in a view:

 
  render_widget :name, :whatever => "yay!"

but it throws error
{:whatever=>"yay!"} is not a symbol

Ahmad Musaffa

unread,
Aug 8, 2014, 7:32:12 PM8/8/14
to cells-an...@googlegroups.com
Oh I have figured it out:

 render_widget :name, :display, :whatever => "yay!"

then
 def display(args)
  .....
 end

Nick Sutterer

unread,
Aug 9, 2014, 6:08:13 PM8/9/14
to cells-an...@googlegroups.com
This definitely needs some redesign, the apotomo API is gettin' old! Thanks!


--
Sie erhalten diese Nachricht, weil Sie in Google Groups E-Mails von der Gruppe "Cells and Apotomo" abonniert haben.
Wenn Sie sich von dieser Gruppe abmelden und keine E-Mails mehr von dieser Gruppe erhalten möchten, senden Sie eine E-Mail an cells-and-apot...@googlegroups.com.
Weitere Optionen finden Sie unter https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages