Hello,
I am trying to create a button on the list page that triggers an action,
like for example a list of type of wood, and the button adds dynamically
upon clicking the number of packages linked to a certain type of wood.
The list of wood should be updated automatically, i am able to add more
wood packages but the list page is not updated automatically. (unless i
refresh)
I tried using render :partial in the function… nothing.
Any idea how to make it work properly without reloading the whole page?
CN
so you have a button that increments the number of packages, but the
number
of packages displayed does not update when the button is clicked to add
another package?
give the element in which you write the number of packages an id, for
example id="<%= ‘wood’ + wood.id.to_s %>".
then in your controller
def incrementing_function
wood = Wood.find(params[:wood_id]
wood.packages += 1
wood.save
render(update) do |page|
page.replace_html “wood” + wood.id.to_s, :partial => ‘partial you
mentioned’, :locals => {:wood => wood}
end
end
if you use the partial you mentioned to render the original number of
packages then you will replace the partial with the same partial,
populated
with the updated wood object.
hope that helps, if not, elaborate on your problem and maybe someone
else
will be able to help.
Ivor
Thanks Ivor,
It is a voting button for a specific candidate in the list.
All programming process is workign fine, the thing is that i want to
enable dynamic update of the # of votes (if possible using ajax)
I have these lines in my candidates list:
<%= form_remote_tag(:url => { :action => 'vote', :id => cand.id },
:update => 'voting' + cand.id.to_s )
%>
<div id="<%= 'voting' + cand.id.to_s %>">
<%=h cand.votes %><br/>
</div>
<%= submit_tag("Add Voter") %>
<%= end_form_tag %>
and the following controller function:
def vote
cand = Candidates.find(params[:id])
cand.votes += 1
cand.save
render(update) do |page|
page.replace_html “voting” + cand.id.to_s, :partial => ‘list’,
:locals => {:candidates => candidates}
end
end
The error i am getting is the following:
“ActionController::DoubleRenderError in CandidatesController#vote
Can only render or redirect once per action”
Costi Nicolaou wrote:
I also created an .RJS file for highliting:
page.visual_effect :highlight, “voting#{@candidates.id}”
Diebold??!!! nooo
Can you pls elaborate on your idea? How the current one is posting
twice?
Thx in advance
Costi Nicolaou wrote:
<%= form_remote_tag(:url => { :action => 'vote', :id => cand.id },
:update => 'voting' + cand.id.to_s )
For a vote, why not use observe_form() and submit the vote at click
time? Why make the user click twice just to vote once?
You don’t work for Diebold, do you?
(
–
Phlip
http://c2.com/cgi/wiki?ZeekLand ← NOT a blog!!
Costi Nicolaou wrote:
Can you pls elaborate on your idea? How the current one is posting
twice?
Look observe_form() up.
Your current plan makes the user click their mouse on the check-box,
then click on the Submit button.
If you instead observe the form, it will post each time the user
changes it. In some usability contexts, such as voting, the post
should be instant. Consider the Rating button on Google G. posts.
In other usability contexts, the users should make many changes and
send them all at once. That’s what Submit buttons are for.
–
Phlip
http://c2.com/cgi/wiki?ZeekLand ← NOT a blog!!