Forum: Ruby on Rails Dynamically uploading a list that's already in a form

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.
Constantin G. (Guest)
on 2007-02-25 21:07
I have the classic case of: Posts, and Categories. When the user submits
a post, he has a drop-down list of categories. I want to put a "Add
category" link next to the list of categories.

This is already inside a form, so a "link_to_remote" that creates a
small AJAX form inside the "submit post" form will not work because that
will mean to embed a form in another form.

I can popup a window that at the end refreshes the parent window or go
to a page where the user can add categories and redirect at the submit
post, but that seems so ten years ago.

Can anybody enlighten me on what's the "best practice" way to update
this categories list in a form? The web 2.0?
ebrad (Guest)
on 2007-03-20 18:34
(Received via mailing list)
Has anyone found a solid solution to this? This would be good for
usability.

On Feb 25, 3:07 pm, Constantin G. <rails-mailing-l...@andreas-
Constantin G. (Guest)
on 2007-03-20 21:14
ebrad wrote:
> Has anyone found a solid solution to this? This would be good for
> usability.
>

Since I didn't got an answer, I've done it the way I thought best: I
made a "false popup" with a div over the form. I used the Redbox plugin
for that.
ebrad (Guest)
on 2007-03-21 19:29
(Received via mailing list)
Yes, that's the way I wanted to do it too, but Redbox was putting the
hidden popup div inside the main form, which I coudn't get to work.
Do you have an example that you could post?

Cheers

Brad W.

On Mar 20, 3:14 pm, Constantin G. <rails-mailing-l...@andreas-
Constantin G. (Guest)
on 2007-03-30 08:46
ebrad wrote:
> Yes, that's the way I wanted to do it too, but Redbox was putting the
> hidden popup div inside the main form, which I coudn't get to work.
> Do you have an example that you could post?
>
> Cheers
>
> Brad W.
>

Put a div named however you want _outside your form_.
In the form, use the :update => 'div_id' parameter. I used the redbox
convention of naming the div.

Copy/pasted from my code:
<%= link_to_remote_redbox 'Edit Container', :update =>
'hidden_content_edit_container_popup',
            :url => {:action => 'edit_container_popup', :pin =>
container.pin } %>

Then, you need to edit redbox_helper.rb. You need to get rid of all that
shit with "id" "hidden_id", and use your variable that you given in
:update.
You also need to tell redbox not to generate the div for you. So you are
left with just two lines of code.


  def link_to_remote_redbox(name, link_to_remote_options = {},
html_options = {})
    link_to_remote_options =
redbox_remote_options(link_to_remote_options,
link_to_remote_options[:update])
    return link_to_remote(name, link_to_remote_options, html_options)
  end

Restart the server, and test. It works for me.

I have the dev website on a subdomain of www.apluscompuservices.com (btw
- dreamhost for rails is really slow). I'm not sure if my client like an
"early launch" so if interested about the url, email me at
removed_email_address@domain.invalid.
werdnativ (Guest)
on 2007-03-30 22:10
(Received via mailing list)
In my app I simply have a submit_to_remote within the larger form...
no need for a nested form. It submits the entire form including the
other fields but I only read the category[:name] param when I receive
it in my CategoriesController#create action.

Inside a larger form...
  <%= text_field_tag 'category[name]' %>
  <%= submit_to_remote 'add_category', 'Add', :url => categories_path
%>

I belive there is a :submit parameter available for submit_to_remote
that should specify which field(s) to submit instead of the whole
form, but I haven't played with that. (See the API doc for
link_to_remote: as I understand it, submit_to_remote uses the same
options.)


On Feb 25, 12:07 pm, Constantin G. <rails-mailing-l...@andreas-
This topic is locked and can not be replied to.