Thanks
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/RHAW38e5gOwJ.
For more options, visit https://groups.google.com/groups/opt_out.
Hi jim
As I am using remote: true I created a update.js.erb and a respond_to do |format| block.
Copied the format html ocde into the update.js.erb and the update process is still working.. so far so good.
But it is unclear to me how to update the
Model.where(model_id: id).sum("attribute") query which is in edit action.
Using html, after update the edit action is called and the query is refreshed. How to get this working with js?
Something like a submit or refreshing the edit action..?
Thanks for sharing..
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/GktAGfGYQm4J.
Sure..
def edit
@booking = Booking.new
@project = Project.find(params[:id])
@main_hours = main_hours_sum(@project.id)
...
end
def main_hours_sum(id)
Booking.where(project_id: id).sum("hour")
end
def update
respond_to do |format|
format.js
end
end
update.js.erb
<% if params[:booking_ids] %>
<% params[:booking_ids].each do %>
<% Booking.update(params[:booking].keys, params[:booking].values).reject { |p| p.errors.empty? } %>
<% end %>
<%end%>
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/aGQY2mvKhoUJ.
o.k.
Now it is like that:
def updateformat.js{ end
if params[:booking_ids]
params[:booking_ids].each do
Booking.update(params[:booking].keys, params[:booking].values).reject { |p| p.errors.empty? }
end
end
respond_to do |format|
end
def main_hours_sum(id)
hours ||= Booking.where(project_id: id).sum("hour")
end
update.js.erbThe alert pops up and shows the correct amount of hours..
alert('<%= @main_hours %>')
Thanks so far.....but I dont have an idea how to update/reset the @main_hours on the edit page where it is shown. As I dont leave this page, no request - no update.
May be my understanding of this process is not enough yet.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Uww8jzoTzJcJ.
Am 20.11.2012 um 13:55 schrieb Jim Ruther Nill <jvn...@gmail.com>:I try to explain..I have this edit form where I can edit hoursOn top of the insert form itself I give Information about the complete amount of hours.
So I ask for the complete amount of hours by asking for the part / main project and add them .When I edit hours in the form.... I want of course not only update the house by form-field, but also actualize the all-together hours. (sum the table)Normally this is done by the submit request parsing the edit action.But now with editing the hour fields with js, this is not happening ......Hope this gets more clear now.
$('#main-hours span').text('<%= @main_hours %>');
Am 20.11.2012 um 14:19 schrieb Jim Ruther Nill <jvn...@gmail.com>:$('#main-hours span').text('<%= @main_hours %>');perfect.. thanks a lot..Now I get the idea..
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.