Forum: Ruby on Rails Why this error ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
460ead051b49c0b2a8e45e46252d4bda?d=identicon&s=25 Tom Ha (tom)
on 2009-01-17 20:07
Hi there,

can somebody enlighten me why this throws an error (when this code is
called):

<% form_remote_tag :url => '/user/agents' do -%>
  <%= button_to_function 'Personal account' do |page| page.replace_html
'newagentpersonal', :partial => 'user/agents/newagentpersonal' end %>
  <div id="newagentpersonal">
  <%= render :partial => 'newagentpersonal' %>
  </div>
  <p><%= submit_tag 'Add' %></p>
<% end -%>


...while this doesn't:


<% form_remote_tag :url => '/user/agents' do -%>
  [--the only difference here: this (button code) line is deleted--]
  <div id="newagentpersonal">
  <%= render :partial => 'newagentpersonal' %>
  </div>
  <p><%= submit_tag 'Add' %></p>
<% end -%>

Firebug reports "missing ) after argument list" (and it's definitely
that second line that causes the error).

How can I make this work?

Thanks a lot for any help!
Tom
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-01-17 21:36
(Received via mailing list)
Tom Ha wrote:

>   <%= button_to_function 'Personal account' do |page| page.replace_html
> 'newagentpersonal', :partial => 'user/agents/newagentpersonal' end %>

What is the 'end' there for? (-:
460ead051b49c0b2a8e45e46252d4bda?d=identicon&s=25 Tom Ha (tom)
on 2009-01-17 21:40
Well, as far as I know, you need to close with "end" as soon as you have
a "do", right?
9a2a53db8e9b4476038c94a64b32833f?d=identicon&s=25 Ryan Bigg (ryan-bigg)
on 2009-01-17 22:17
(Received via mailing list)
Try putting a line break after the |page| and before the "end"
-----
Ryan Bigg
Freelancer
http://frozenplague.net
460ead051b49c0b2a8e45e46252d4bda?d=identicon&s=25 Tom Ha (tom)
on 2009-01-17 22:26
I tried, the problem remains...
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-01-17 23:31
(Received via mailing list)
Have you had a look at the page source to see what the
button_to_function is
generating?

Colin
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-01-18 06:05
(Received via mailing list)
Tom Ha wrote:

> I tried, the problem remains...

Here's the issue. Sorry I didn't post it before, but Vista locked up as
usual.
Whine whine whine.

Anyway, this does not print out 'yo':

   puts
   'yo'

You can't put the argument to a method on a new line like that. It's the
same as
puts; 'yo'. The first statement outputs a linefeed, and the second one
thinks
about 'yo' briefly, then throws it away (or returns it).

Your replace_html has a linefeed between itself and its first argument.

Tips: Write more unit tests, and don't follow the example of the Rails
gurus.
Never cram everything into one line! Neat formatting would have saved
you from
learning how Ruby parses method arguments...

New question: How is this supposed to work?

<%=
   button_to_function 'Personal account' do |rjs|
     rjs.replace_html 'newagentpersonal',   # this comma , is okay!
          :partial => 'user/agents/newagentpersonal'
   end
%>

(I renamed 'page' to 'rjs' because the world has too danged many
variables
called 'page' in it!)

I thought that :partial would run on the server side, cook a page, and
let you
send it over a wire. So maybe that usage of .replace_html is only going
to cram
your HTML with a big JavaScript string containing more HTML. Maybe you
need
that, but if I tried to cook that partial with fresh variables,
collected from
the page at runtime, they would not affect the partial's contents. And
that, in
turn, would leave me with less reasons to use a partial!

--
   Phlip
460ead051b49c0b2a8e45e46252d4bda?d=identicon&s=25 Tom Ha (tom)
on 2009-01-18 16:57
Thanks for your hints, guys!

Actually, my aim was the following:

Show the user only the *mandatory* (or: most basic) fields of a form
that is to be submitted. That way, the user isn't put off by a tons of
(maybe even unnecessary) fields (depending on what kind of user she is).

My idea to accomplish that was:

Have partials that can contain partials (and so on...). Every partial
could be called with a "button_to_function"-button located in the
"parent partial". In an extreme case, you could end up with a big,
tree-like partial structure.

Bus as Phlip pointed out, it's apparently not possible for Rails to
manage such an "interlocked" partials structure using
"page.replace_html" (Ajax).

So if anybody out there has an idea of how to build such a more
user-friendly/"customizable-on-the-fly" form, please let me/us know,
thanks!

Tom
460ead051b49c0b2a8e45e46252d4bda?d=identicon&s=25 Tom Ha (tom)
on 2009-01-18 23:37
Solution, in case anyone still wonders (obvious for non-n00bs):

To have partials in partials (etc.), like a tree-like structure, and at
the same time to be able to let the user choose which partials to view
(which "branch of the tree" to open or close, for example in a form that
should be customized by the user, on-the-fly), just put the
"page.replace_html" code (Ajax) in the *controller*.

(DON'T use a "button_to_function" *within* such a partial!)

Tom
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-01-18 23:53
(Received via mailing list)
Tom Ha wrote:

> Solution, in case anyone still wonders (obvious for non-n00bs):
>
> To have partials in partials (etc.), like a tree-like structure, and at
> the same time to be able to let the user choose which partials to view
> (which "branch of the tree" to open or close, for example in a form that
> should be customized by the user, on-the-fly), just put the
> "page.replace_html" code (Ajax) in the *controller*.

Yup. That's what I implied, but I could not figure out the code's actual
intent,
so I couldn't say that.

> (DON'T use a "button_to_function" *within* such a partial!)

Yet sometimes a button_to_function can pull in a static partial, and
that's what
you need... (-:
This topic is locked and can not be replied to.