O.k., so Rails is killing my productivity; I could manually script this,
but I''m trying to do it the "rails way."
I have a page that lists landmarks (schools, parks, monuments, etc.), 10
per page, paginated. Works great. For each one, I want to be able to
specify the type of landmark it is (school, park, etc.) by selecting it
from a drop-down box, then just have Ajax update the thing on the back
end. Not so great. If this isn''t (apparently) the most difficult task
to accomplish in Rails. None of the suggestions on the mailing list
archives seem to work. Any other suggestions?
Here''s a snippet of my list page:
<% @landmarks.each_with_index do |landmark, index| %>
<form_remote_tag :update => "update_div", :url => { :action
=>
"update", :id => landmark }>
<tr id ="row_<%= landmark.id %>" class="<%= index %
2 == 0 ? "even" :
"odd" %>">
<td><%= link_to(landmark.name, { :action => "edit", :id
=>
landmark.id }) %></td>
<td><%= landmark.city %></td>
<td><%= select_tag "landmark[landmark_type]",
options_for_select([""]
+ @landmark_types.collect {|landmark_type| landmark_type.name},
landmark.landmark_type) %><%= submit_tag %></td>
<td><%= landmark.latitude %></td>
<td><%= landmark.longitude %></td>
</tr>
<%= end_form_tag %>
<% end %>
Right now I''ve got the submit button working (I''d rather just
select
from the list and do an onchange="submit()," but that doesn''t
work);
however, the select tag value does not get submitted.
If I put { :onchange => "submit()" } at the end of my select_tag,
everything works great, except that I submit the form to the update
method on the controller, and because it''s not Ajax, I get shoved to
the
show page.
Why does this seem like the simplest, most requested feature, yet it''s
just not supported in any way, shape, or form? Am I just missing
something?
Sorry, but it''s very frustrating.
By the way, observe_field function seems to be broken in 0.13.1. I''ve
tried using this per other postings. It never finds the "element"
value
of the select tag, no matter what I do.
I too thought the observe field was broken. My error was syntax and position of the observe tag field. Check your syntax. For testing purposes set a shorter frequency. Make sure the observe field tag falls after the field to observe in your code. John Sean Bowman wrote:>O.k., so Rails is killing my productivity; I could manually script this, >but I''m trying to do it the "rails way." > >I have a page that lists landmarks (schools, parks, monuments, etc.), 10 >per page, paginated. Works great. For each one, I want to be able to >specify the type of landmark it is (school, park, etc.) by selecting it >from a drop-down box, then just have Ajax update the thing on the back >end. Not so great. If this isn''t (apparently) the most difficult task >to accomplish in Rails. None of the suggestions on the mailing list >archives seem to work. Any other suggestions? > >Here''s a snippet of my list page: > ><% @landmarks.each_with_index do |landmark, index| %> > <form_remote_tag :update => "update_div", :url => { :action => >"update", :id => landmark }> > <tr id ="row_<%= landmark.id %>" class="<%= index % 2 == 0 ? "even" : >"odd" %>"> > <td><%= link_to(landmark.name, { :action => "edit", :id => >landmark.id }) %></td> > <td><%= landmark.city %></td> > <td><%= select_tag "landmark[landmark_type]", options_for_select([""] >+ @landmark_types.collect {|landmark_type| landmark_type.name}, >landmark.landmark_type) %><%= submit_tag %></td> > <td><%= landmark.latitude %></td> > <td><%= landmark.longitude %></td> > </tr> > <%= end_form_tag %> ><% end %> > >Right now I''ve got the submit button working (I''d rather just select >from the list and do an onchange="submit()," but that doesn''t work); >however, the select tag value does not get submitted. > >If I put { :onchange => "submit()" } at the end of my select_tag, >everything works great, except that I submit the form to the update >method on the controller, and because it''s not Ajax, I get shoved to the >show page. > >Why does this seem like the simplest, most requested feature, yet it''s >just not supported in any way, shape, or form? Am I just missing >something? > >Sorry, but it''s very frustrating. > >By the way, observe_field function seems to be broken in 0.13.1. I''ve >tried using this per other postings. It never finds the "element" value >of the select tag, no matter what I do. > > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > > >
Here''s what I finally wound up with, which seems to work:
<% @landmarks.each_with_index do |landmark, index| %>
<%= form_remote_tag :update => "update_div", :url => {
:action => "update", :id => landmark } %>
<input type="hidden" name="test"
value="bites">
<tr id ="row_<%= landmark.id %>" class="<%= index %
2 == 0 ? "even" : "odd" %>">
<td><%= link_to(landmark.name, { :action => "edit", :id
=> landmark.id }) %></td>
<td><%= landmark.city %></td>
<td><%= select_tag "landmark[landmark_type]",
options_for_select([""] + @landmark_types.collect {|landmark_type|
landmark_type.name}, landmark.landmark_type),
{ :onchange => remote_function(:update => "update_div", :url
=> { :action => "update", :id => landmark }, :with =>
"Form.Element.serialize(this)", :method =>
"''post''") }%><%= submit_tag %></td>
<td><%= landmark.latitude %></td>
<td><%= landmark.longitude %></td>
</tr>
<%= end_form_tag %>
<% end %>
I don''t think I need the form_remote_tag anymore, since the select_tag
is handling the AJAX call, but what the heck.
I think there might be a problem with Prototype and having more than one
form on a page. Putting in a specific name and ID for each form didn''t
seem to help at all. I can get away with the above Form.Elements call
because I''m passing in "this," so Prototype doesn''t
have to look for the
correct form. The fellow I''m working on this project with is trying to
hunt down the problem now. Personally, after 8 hours of fighting with
Rails on this one topic, I''m just glad it''s finally working.
On Tue, 2005-09-20 at 13:16 -0600, Sean Bowman wrote:> O.k., so Rails is killing my productivity; I could manually script this,
> but I''m trying to do it the "rails way."
>
> I have a page that lists landmarks (schools, parks, monuments, etc.), 10
> per page, paginated. Works great. For each one, I want to be able to
> specify the type of landmark it is (school, park, etc.) by selecting it
> from a drop-down box, then just have Ajax update the thing on the back
> end. Not so great. If this isn''t (apparently) the most difficult
task
> to accomplish in Rails. None of the suggestions on the mailing list
> archives seem to work. Any other suggestions?
>
> Here''s a snippet of my list page:
>
> <% @landmarks.each_with_index do |landmark, index| %>
> <form_remote_tag :update => "update_div", :url => {
:action =>
> "update", :id => landmark }>
> <tr id ="row_<%= landmark.id %>" class="<%=
index % 2 == 0 ? "even" :
> "odd" %>">
> <td><%= link_to(landmark.name, { :action => "edit",
:id =>
> landmark.id }) %></td>
> <td><%= landmark.city %></td>
> <td><%= select_tag "landmark[landmark_type]",
options_for_select([""]
> + @landmark_types.collect {|landmark_type| landmark_type.name},
> landmark.landmark_type) %><%= submit_tag %></td>
> <td><%= landmark.latitude %></td>
> <td><%= landmark.longitude %></td>
> </tr>
> <%= end_form_tag %>
> <% end %>
>
> Right now I''ve got the submit button working (I''d rather
just select
> from the list and do an onchange="submit()," but that
doesn''t work);
> however, the select tag value does not get submitted.
>
> If I put { :onchange => "submit()" } at the end of my
select_tag,
> everything works great, except that I submit the form to the update
> method on the controller, and because it''s not Ajax, I get shoved
to the
> show page.
>
> Why does this seem like the simplest, most requested feature, yet
it''s
> just not supported in any way, shape, or form? Am I just missing
> something?
>
> Sorry, but it''s very frustrating.
>
> By the way, observe_field function seems to be broken in 0.13.1.
I''ve
> tried using this per other postings. It never finds the
"element" value
> of the select tag, no matter what I do.
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
--
Sean Bowman
Lab Architect
Local Matters, Inc.
1517 Blake Street, Floor Two
Denver, CO 80202
sbowman-VsM5TWebDq2iu113P13oHA@public.gmane.org
www.localmatters.com
O 303-572-1122 x 201
C 303-808-1718
F 303-572-1123
Also figured out you apparently can''t put a form tag around a tr tag...at least not in Firefox. On Tue, 2005-09-20 at 14:23 -0600, Sean Bowman wrote:> Here''s what I finally wound up with, which seems to work: > > <% @landmarks.each_with_index do |landmark, index| %> > <%= form_remote_tag :update => "update_div", :url => { :action => "update", :id => landmark } %> > <input type="hidden" name="test" value="bites"> > <tr id ="row_<%= landmark.id %>" class="<%= index % 2 == 0 ? "even" : "odd" %>"> > <td><%= link_to(landmark.name, { :action => "edit", :id => landmark.id }) %></td> > <td><%= landmark.city %></td> > <td><%= select_tag "landmark[landmark_type]", options_for_select([""] + @landmark_types.collect {|landmark_type| landmark_type.name}, landmark.landmark_type), > { :onchange => remote_function(:update => "update_div", :url => { :action => "update", :id => landmark }, :with => "Form.Element.serialize(this)", :method => "''post''") }%><%= submit_tag %></td> > <td><%= landmark.latitude %></td> > <td><%= landmark.longitude %></td> > </tr> > <%= end_form_tag %> > <% end %> > > I don''t think I need the form_remote_tag anymore, since the select_tag > is handling the AJAX call, but what the heck. > > I think there might be a problem with Prototype and having more than one > form on a page. Putting in a specific name and ID for each form didn''t > seem to help at all. I can get away with the above Form.Elements call > because I''m passing in "this," so Prototype doesn''t have to look for the > correct form. The fellow I''m working on this project with is trying to > hunt down the problem now. Personally, after 8 hours of fighting with > Rails on this one topic, I''m just glad it''s finally working. > > On Tue, 2005-09-20 at 13:16 -0600, Sean Bowman wrote: > > O.k., so Rails is killing my productivity; I could manually script this, > > but I''m trying to do it the "rails way." > > > > I have a page that lists landmarks (schools, parks, monuments, etc.), 10 > > per page, paginated. Works great. For each one, I want to be able to > > specify the type of landmark it is (school, park, etc.) by selecting it > > from a drop-down box, then just have Ajax update the thing on the back > > end. Not so great. If this isn''t (apparently) the most difficult task > > to accomplish in Rails. None of the suggestions on the mailing list > > archives seem to work. Any other suggestions? > > > > Here''s a snippet of my list page: > > > > <% @landmarks.each_with_index do |landmark, index| %> > > <form_remote_tag :update => "update_div", :url => { :action => > > "update", :id => landmark }> > > <tr id ="row_<%= landmark.id %>" class="<%= index % 2 == 0 ? "even" : > > "odd" %>"> > > <td><%= link_to(landmark.name, { :action => "edit", :id => > > landmark.id }) %></td> > > <td><%= landmark.city %></td> > > <td><%= select_tag "landmark[landmark_type]", options_for_select([""] > > + @landmark_types.collect {|landmark_type| landmark_type.name}, > > landmark.landmark_type) %><%= submit_tag %></td> > > <td><%= landmark.latitude %></td> > > <td><%= landmark.longitude %></td> > > </tr> > > <%= end_form_tag %> > > <% end %> > > > > Right now I''ve got the submit button working (I''d rather just select > > from the list and do an onchange="submit()," but that doesn''t work); > > however, the select tag value does not get submitted. > > > > If I put { :onchange => "submit()" } at the end of my select_tag, > > everything works great, except that I submit the form to the update > > method on the controller, and because it''s not Ajax, I get shoved to the > > show page. > > > > Why does this seem like the simplest, most requested feature, yet it''s > > just not supported in any way, shape, or form? Am I just missing > > something? > > > > Sorry, but it''s very frustrating. > > > > By the way, observe_field function seems to be broken in 0.13.1. I''ve > > tried using this per other postings. It never finds the "element" value > > of the select tag, no matter what I do. > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > -- > Sean Bowman > Lab Architect > Local Matters, Inc. > > 1517 Blake Street, Floor Two > Denver, CO 80202 > sbowman-VsM5TWebDq2iu113P13oHA@public.gmane.org > www.localmatters.com > O 303-572-1122 x 201 > C 303-808-1718 > F 303-572-1123 > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- Sean Bowman Lab Architect Local Matters, Inc. 1517 Blake Street, Floor Two Denver, CO 80202 sbowman-VsM5TWebDq2iu113P13oHA@public.gmane.org www.localmatters.com O 303-572-1122 x 201 C 303-808-1718 F 303-572-1123
One of the most important things when it comes to CSS and AJAX is being aware of web standards and valid documents. A lot of these technologies need to be able to understand the markup in your page and they will encounter some problems if your document is invalid. If there''s something that''s not working right, take a few seconds and validate your (X)HTML. There''s a wonderful extension for Firefox called "Web Developer Toolbar" that makes validation a snap. For example, form tags cannot reside inside of a table row. It''s invalid markup. (They can reside in a table cell though). It''s not even a good idea anyway because the current trend is to separate content (html) from design. Many believe that tables should be used only to represent tabular data and not used for layout purposes. I probably don''t need to say this, but IE is VERY forgiving when it comes to malformed HTML. However, the more you embrace web standards, the more you will come to realize that IE''s "forgiveness" is actually a curse at best. On 9/20/05, Sean Bowman <sbowman-VsM5TWebDq2iu113P13oHA@public.gmane.org> wrote:> > Also figured out you apparently can''t put a form tag around a tr > tag...at least not in Firefox. > > On Tue, 2005-09-20 at 14:23 -0600, Sean Bowman wrote: > > Here''s what I finally wound up with, which seems to work: > > > > <% @landmarks.each_with_index do |landmark, index| %> > > <%= form_remote_tag :update => "update_div", :url => { :action => > "update", :id => landmark } %> > > <input type="hidden" name="test" value="bites"> > > <tr id ="row_<%= landmark.id <http://landmark.id> %>" class="<%= index % > 2 == 0 ? "even" : "odd" %>"> > > <td><%= link_to(landmark.name <http://landmark.name>, { :action => > "edit", :id => landmark.id <http://landmark.id> }) %></td> > > <td><%= landmark.city %></td> > > <td><%= select_tag "landmark[landmark_type]", options_for_select([""] + > @landmark_types.collect {|landmark_type| landmark_type.name}, > landmark.landmark_type), > > { :onchange => remote_function(:update => "update_div", :url => { > :action => "update", :id => landmark }, :with => "Form.Element.serialize(this)", > :method => "''post''") }%><%= submit_tag %></td> > > <td><%= landmark.latitude %></td> > > <td><%= landmark.longitude %></td> > > </tr> > > <%= end_form_tag %> > > <% end %> > > > > I don''t think I need the form_remote_tag anymore, since the select_tag > > is handling the AJAX call, but what the heck. > > > > I think there might be a problem with Prototype and having more than one > > form on a page. Putting in a specific name and ID for each form didn''t > > seem to help at all. I can get away with the above Form.Elements call > > because I''m passing in "this," so Prototype doesn''t have to look for the > > correct form. The fellow I''m working on this project with is trying to > > hunt down the problem now. Personally, after 8 hours of fighting with > > Rails on this one topic, I''m just glad it''s finally working. > > > > On Tue, 2005-09-20 at 13:16 -0600, Sean Bowman wrote: > > > O.k., so Rails is killing my productivity; I could manually script > this, > > > but I''m trying to do it the "rails way." > > > > > > I have a page that lists landmarks (schools, parks, monuments, etc.), > 10 > > > per page, paginated. Works great. For each one, I want to be able to > > > specify the type of landmark it is (school, park, etc.) by selecting > it > > > from a drop-down box, then just have Ajax update the thing on the back > > > end. Not so great. If this isn''t (apparently) the most difficult task > > > to accomplish in Rails. None of the suggestions on the mailing list > > > archives seem to work. Any other suggestions? > > > > > > Here''s a snippet of my list page: > > > > > > <% @landmarks.each_with_index do |landmark, index| %> > > > <form_remote_tag :update => "update_div", :url => { :action => > > > "update", :id => landmark }> > > > <tr id ="row_<%= landmark.id <http://landmark.id> %>" class="<%= index > % 2 == 0 ? "even" : > > > "odd" %>"> > > > <td><%= link_to(landmark.name <http://landmark.name>, { :action => > "edit", :id => > > > landmark.id <http://landmark.id> }) %></td> > > > <td><%= landmark.city %></td> > > > <td><%= select_tag "landmark[landmark_type]", options_for_select([""] > > > + @landmark_types.collect {|landmark_type| landmark_type.name}, > > > landmark.landmark_type) %><%= submit_tag %></td> > > > <td><%= landmark.latitude %></td> > > > <td><%= landmark.longitude %></td> > > > </tr> > > > <%= end_form_tag %> > > > <% end %> > > > > > > Right now I''ve got the submit button working (I''d rather just select > > > from the list and do an onchange="submit()," but that doesn''t work); > > > however, the select tag value does not get submitted. > > > > > > If I put { :onchange => "submit()" } at the end of my select_tag, > > > everything works great, except that I submit the form to the update > > > method on the controller, and because it''s not Ajax, I get shoved to > the > > > show page. > > > > > > Why does this seem like the simplest, most requested feature, yet it''s > > > just not supported in any way, shape, or form? Am I just missing > > > something? > > > > > > Sorry, but it''s very frustrating. > > > > > > By the way, observe_field function seems to be broken in 0.13.1. I''ve > > > tried using this per other postings. It never finds the "element" > value > > > of the select tag, no matter what I do. > > > > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > -- > > Sean Bowman > > Lab Architect > > Local Matters, Inc. > > > > 1517 Blake Street, Floor Two > > Denver, CO 80202 > > sbowman-VsM5TWebDq2iu113P13oHA@public.gmane.org > > www.localmatters.com <http://www.localmatters.com> > > O 303-572-1122 x 201 > > C 303-808-1718 > > F 303-572-1123 > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > -- > Sean Bowman > Lab Architect > Local Matters, Inc. > > 1517 Blake Street, Floor Two > Denver, CO 80202 > sbowman-VsM5TWebDq2iu113P13oHA@public.gmane.org > www.localmatters.com <http://www.localmatters.com> > O 303-572-1122 x 201 > C 303-808-1718 > F 303-572-1123 > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 9/20/05, Brian Hogan <bphogan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > If there''s something that''s not working right, take a few seconds and > validate your (X)HTML. There''s a wonderful extension for Firefox called "Web > Developer Toolbar" that makes validation a snap.Yes, and another that validates automatically upon viewing the source https://addons.mozilla.org/extensions/moreinfo.php?application=firefox&id=249 FIrefox rocks! -- Chris Martin Web Developer Open Source & Web Standards Advocate http://www.chriscodes.com/