On Mon, Nov 19, 2012 at 10:25 PM, Werner wrote:

On my edit page I can update values using ajax.

In my edit action I also have something like: Model.where(model_id:
id).sum("attribute")
As the edit action is not executed anymore, I dont get a proper result
after I add some new value, have to reload the page.

How is the best way to actualize the sum after edit.. ?
Are you updating the values by calling $.ajax or just passing in remote:
true on your forms?

If you use $.ajax, I suggest that you pass in the sum as json which $.ajax
can process. If you're
using remote: true, you can create an update.js.erb or update.js.haml which
will be rendered
after you update.

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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@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.



--
-------------------------------------------------------------
visit my blog at http://jimlabs.heroku.com

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Werner at Nov 19, 2012 at 2:55 pm
    On my edit page I can update values using ajax.

    In my edit action I also have something like: Model.where(model_id:
    id).sum("attribute")
    As the edit action is not executed anymore, I dont get a proper result
    after I add some new value, have to reload the page.

    How is the best way to actualize the sum after edit.. ?

    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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.
  • Werner at Nov 20, 2012 at 8:53 am
    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..





    Am Montag, 19. November 2012 15:30:42 UTC+1 schrieb jim:



    On Mon, Nov 19, 2012 at 10:25 PM, Werner <webagent...@googlemail.com<javascript:>
    wrote:
    On my edit page I can update values using ajax.

    In my edit action I also have something like: Model.where(model_id:
    id).sum("attribute")
    As the edit action is not executed anymore, I dont get a proper result
    after I add some new value, have to reload the page.

    How is the best way to actualize the sum after edit.. ?
    Are you updating the values by calling $.ajax or just passing in remote:
    true on your forms?

    If you use $.ajax, I suggest that you pass in the sum as json which $.ajax
    can process. If you're
    using remote: true, you can create an update.js.erb or update.js.haml
    which will be rendered
    after you update.

    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<javascript:>
    .
    To unsubscribe from this group, send email to
    rubyonrails-ta...@googlegroups.com <javascript:>.
    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.



    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com
    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/GktAGfGYQm4J.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jim Ruther Nill at Nov 20, 2012 at 8:59 am
    Hi!
    On Tue, Nov 20, 2012 at 4:53 PM, Werner wrote:

    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.
    Can you paste in part of the edit template where you use the result of this
    query?

    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..?
    Can you also paste your edit and update actions so we can work on the code
    level.

    Thanks for sharing..



    Am Montag, 19. November 2012 15:30:42 UTC+1 schrieb jim:


    On Mon, Nov 19, 2012 at 10:25 PM, Werner wrote:

    On my edit page I can update values using ajax.

    In my edit action I also have something like: Model.where(model_id:
    id).sum("attribute")
    As the edit action is not executed anymore, I dont get a proper result
    after I add some new value, have to reload the page.

    How is the best way to actualize the sum after edit.. ?
    Are you updating the values by calling $.ajax or just passing in remote:
    true on your forms?

    If you use $.ajax, I suggest that you pass in the sum as json which
    $.ajax can process. If you're
    using remote: true, you can create an update.js.erb or update.js.haml
    which will be rendered
    after you update.

    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<https://groups.google.com/d/msg/rubyonrails-talk/-/RHAW38e5gOwJ>
    .
    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .



    --
    ------------------------------**------------------------------**-
    visit my blog at http://jimlabs.heroku.com
    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msg/rubyonrails-talk/-/GktAGfGYQm4J.

    For more options, visit https://groups.google.com/groups/opt_out.



    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Werner at Nov 20, 2012 at 9:52 am
    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%>






    Am Dienstag, 20. November 2012 09:59:58 UTC+1 schrieb jim:

    Hi!

    On Tue, Nov 20, 2012 at 4:53 PM, Werner <webagent...@googlemail.com<javascript:>
    wrote:
    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.
    Can you paste in part of the edit template where you use the result of
    this query?

    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..?
    Can you also paste your edit and update actions so we can work on the code
    level.

    Thanks for sharing..



    Am Montag, 19. November 2012 15:30:42 UTC+1 schrieb jim:


    On Mon, Nov 19, 2012 at 10:25 PM, Werner wrote:

    On my edit page I can update values using ajax.

    In my edit action I also have something like: Model.where(model_id:
    id).sum("attribute")
    As the edit action is not executed anymore, I dont get a proper result
    after I add some new value, have to reload the page.

    How is the best way to actualize the sum after edit.. ?
    Are you updating the values by calling $.ajax or just passing in remote:
    true on your forms?

    If you use $.ajax, I suggest that you pass in the sum as json which
    $.ajax can process. If you're
    using remote: true, you can create an update.js.erb or update.js.haml
    which will be rendered
    after you update.

    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<https://groups.google.com/d/msg/rubyonrails-talk/-/RHAW38e5gOwJ>
    .
    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .



    --
    ------------------------------**------------------------------**-
    visit my blog at http://jimlabs.heroku.com
    --
    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<javascript:>
    .
    To unsubscribe from this group, send email to
    rubyonrails-ta...@googlegroups.com <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msg/rubyonrails-talk/-/GktAGfGYQm4J.

    For more options, visit https://groups.google.com/groups/opt_out.



    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com
    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/aGQY2mvKhoUJ.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jim Ruther Nill at Nov 20, 2012 at 10:04 am

    On Tue, Nov 20, 2012 at 5:46 PM, Werner wrote:

    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%>
    You need to move the logic in update.js.erb to the update action. I was
    looking for
    the edit template. I'd like to see how you use the @main_hours variable.
    What I'm thinking
    is this on this update action and erb.

    def update
    @project = ... #fetch project here

    # move your logic in the view here
    # there's something missing here :D
    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|
    format.html
    format.js { @main_hours = main_hours_sum(@project.id) }
    end
    end

    # update.js.erb
    # use @main_hours to update whatever you need to update on the view

    alert('<%= @main_hours %>')






    Am Dienstag, 20. November 2012 09:59:58 UTC+1 schrieb jim:

    Hi!
    On Tue, Nov 20, 2012 at 4:53 PM, Werner wrote:

    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.
    Can you paste in part of the edit template where you use the result of
    this query?

    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..?
    Can you also paste your edit and update actions so we can work on the code
    level.

    Thanks for sharing..



    Am Montag, 19. November 2012 15:30:42 UTC+1 schrieb jim:


    On Mon, Nov 19, 2012 at 10:25 PM, Werner wrote:

    On my edit page I can update values using ajax.

    In my edit action I also have something like: Model.where(model_id:
    id).sum("attribute")
    As the edit action is not executed anymore, I dont get a proper result
    after I add some new value, have to reload the page.

    How is the best way to actualize the sum after edit.. ?
    Are you updating the values by calling $.ajax or just passing in
    remote: true on your forms?

    If you use $.ajax, I suggest that you pass in the sum as json which
    $.ajax can process. If you're
    using remote: true, you can create an update.js.erb or update.js.haml
    which will be rendered
    after you update.

    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/*
    *ms**g/rubyonrails-talk/-/**RHAW38e5g**OwJ<https://groups.google.com/d/msg/rubyonrails-talk/-/RHAW38e5gOwJ>
    .
    For more options, visit https://groups.google.com/**grou**ps/opt_out<https://groups.google.com/groups/opt_out>
    .



    --
    ------------------------------****------------------------------****-
    visit my blog at http://jimlabs.heroku.com
    --
    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/-/**GktAGfGYQm4J<https://groups.google.com/d/msg/rubyonrails-talk/-/GktAGfGYQm4J>
    .

    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .



    --
    ------------------------------**------------------------------**-
    visit my blog at http://jimlabs.heroku.com
    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msg/rubyonrails-talk/-/aGQY2mvKhoUJ.

    For more options, visit https://groups.google.com/groups/opt_out.



    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Werner at Nov 20, 2012 at 11:48 am
    o.k.
    Now it is like that:

    def update
    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|
    format.js{
    @project = Project.find(params[:id])
    @main_hours = main_hours_sum(@project.id)
    }
    end
    end

    def main_hours_sum(id)
    hours ||= Booking.where(project_id: id).sum("hour")
    end


    update.js.erb
    alert('<%= @main_hours %>')

    The alert pops up and shows the correct amount of 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.

    Greetings



    Am Dienstag, 20. November 2012 11:04:53 UTC+1 schrieb jim:



    On Tue, Nov 20, 2012 at 5:46 PM, Werner <webagent...@googlemail.com<javascript:>
    wrote:
    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%>
    You need to move the logic in update.js.erb to the update action. I was
    looking for
    the edit template. I'd like to see how you use the @main_hours variable.
    What I'm thinking
    is this on this update action and erb.

    def update
    @project = ... #fetch project here

    # move your logic in the view here
    # there's something missing here :D
    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|
    format.html
    format.js { @main_hours = main_hours_sum(@project.id) }
    end
    end

    # update.js.erb
    # use @main_hours to update whatever you need to update on the view

    alert('<%= @main_hours %>')






    Am Dienstag, 20. November 2012 09:59:58 UTC+1 schrieb jim:

    Hi!
    On Tue, Nov 20, 2012 at 4:53 PM, Werner wrote:

    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.
    Can you paste in part of the edit template where you use the result of
    this query?

    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..?
    Can you also paste your edit and update actions so we can work on the
    code
    level.

    Thanks for sharing..



    Am Montag, 19. November 2012 15:30:42 UTC+1 schrieb jim:



    On Mon, Nov 19, 2012 at 10:25 PM, Werner <webagent...@googlemail.**com
    wrote:
    On my edit page I can update values using ajax.

    In my edit action I also have something like: Model.where(model_id:
    id).sum("attribute")
    As the edit action is not executed anymore, I dont get a proper
    result after I add some new value, have to reload the page.

    How is the best way to actualize the sum after edit.. ?
    Are you updating the values by calling $.ajax or just passing in
    remote: true on your forms?

    If you use $.ajax, I suggest that you pass in the sum as json which
    $.ajax can process. If you're
    using remote: true, you can create an update.js.erb or update.js.haml
    which will be rendered
    after you update.

    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/
    **ms**g/rubyonrails-talk/-/**RHAW38e5g**OwJ<https://groups.google.com/d/msg/rubyonrails-talk/-/RHAW38e5gOwJ>
    .
    For more options, visit https://groups.google.com/**grou**ps/opt_out<https://groups.google.com/groups/opt_out>
    .



    --
    ------------------------------****------------------------------****-
    visit my blog at http://jimlabs.heroku.com
    --
    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/-/**GktAGfGYQm4J<https://groups.google.com/d/msg/rubyonrails-talk/-/GktAGfGYQm4J>
    .

    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .



    --
    ------------------------------**------------------------------**-
    visit my blog at http://jimlabs.heroku.com
    --
    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<javascript:>
    .
    To unsubscribe from this group, send email to
    rubyonrails-ta...@googlegroups.com <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msg/rubyonrails-talk/-/aGQY2mvKhoUJ.

    For more options, visit https://groups.google.com/groups/opt_out.



    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com
    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Uww8jzoTzJcJ.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jim Ruther Nill at Nov 20, 2012 at 12:22 pm

    On Tue, Nov 20, 2012 at 7:48 PM, Werner wrote:

    o.k.
    Now it is like that:

    def update

    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|
    format.js{

    @project = Project.find(params[:id])
    @main_hours = main_hours_sum(@project.id)
    }
    end
    end

    def main_hours_sum(id)
    hours ||= Booking.where(project_id: id).sum("hour")
    end


    update.js.erb

    alert('<%= @main_hours %>')

    The alert pops up and shows the correct amount of 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.
    If you can show us the code of your edit template, I can help you with the
    javascript
    to update the total number of hours.

    Greetings



    Am Dienstag, 20. November 2012 11:04:53 UTC+1 schrieb jim:


    On Tue, Nov 20, 2012 at 5:46 PM, Werner wrote:

    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%>
    You need to move the logic in update.js.erb to the update action. I was
    looking for
    the edit template. I'd like to see how you use the @main_hours variable.
    What I'm thinking
    is this on this update action and erb.

    def update
    @project = ... #fetch project here

    # move your logic in the view here
    # there's something missing here :D
    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|
    format.html
    format.js { @main_hours = main_hours_sum(@project.id) }
    end
    end

    # update.js.erb
    # use @main_hours to update whatever you need to update on the view

    alert('<%= @main_hours %>')






    Am Dienstag, 20. November 2012 09:59:58 UTC+1 schrieb jim:

    Hi!
    On Tue, Nov 20, 2012 at 4:53 PM, Werner wrote:

    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.
    Can you paste in part of the edit template where you use the result of
    this query?

    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..?
    Can you also paste your edit and update actions so we can work on the
    code
    level.

    Thanks for sharing..



    Am Montag, 19. November 2012 15:30:42 UTC+1 schrieb jim:



    On Mon, Nov 19, 2012 at 10:25 PM, Werner <webagent...@googlemail.**
    com> wrote:
    On my edit page I can update values using ajax.

    In my edit action I also have something like: Model.where(model_id:
    id).sum("attribute")
    As the edit action is not executed anymore, I dont get a proper
    result after I add some new value, have to reload the page.

    How is the best way to actualize the sum after edit.. ?
    Are you updating the values by calling $.ajax or just passing in
    remote: true on your forms?

    If you use $.ajax, I suggest that you pass in the sum as json which
    $.ajax can process. If you're
    using remote: true, you can create an update.js.erb or update.js.haml
    which will be rendered
    after you update.

    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/**ms****g/rubyonrails-talk/-/**RHAW38e5g
    ****OwJ<https://groups.google.com/d/msg/rubyonrails-talk/-/RHAW38e5gOwJ>
    .
    For more options, visit https://groups.google.com/**grou****
    ps/opt_out <https://groups.google.com/groups/opt_out>.



    --
    ------------------------------******------------------------------***
    ***-
    visit my blog at http://jimlabs.heroku.com
    --
    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/*
    *ms**g/rubyonrails-talk/-/**GktAGfGYQ**m4J<https://groups.google.com/d/msg/rubyonrails-talk/-/GktAGfGYQm4J>
    .

    For more options, visit https://groups.google.com/**grou**ps/opt_out<https://groups.google.com/groups/opt_out>
    .



    --
    ------------------------------****------------------------------****-
    visit my blog at http://jimlabs.heroku.com
    --
    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/-/**aGQY2mvKhoUJ<https://groups.google.com/d/msg/rubyonrails-talk/-/aGQY2mvKhoUJ>
    .

    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .



    --
    ------------------------------**------------------------------**-
    visit my blog at http://jimlabs.heroku.com
    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msg/rubyonrails-talk/-/Uww8jzoTzJcJ.

    For more options, visit https://groups.google.com/groups/opt_out.



    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Werner Laude at Nov 20, 2012 at 12:52 pm
    here...is the essential

    def edit
    @booking = Booking.new

    @project = Project.find(params[:id])
    @partprojects = Project.find_all_by_parent_id(@project.id)

    @bookings = Booking.zwischen(start, ende)

    @main_hours = main_hours_sum(@project.id)
    @part_hours = part_hours_sum(@partprojects.id)
    @all_hours = @main_hours + @part_hours
    end

    form
    <%= simple_form_for @booking, :url => booking_path, :remote => true, :method => :put do %>
    <% @bookings.each do |booking|%>

    <%= fields_for "booking[]", booking do |f|%>
    <%= f.text_field :hour, :class => 'submittable' %>
    <%= hidden_field_tag "booking_ids[]", booking.id %>
    <% end %>

    <% end %>

    coffee
    $(".submittable").live "change", ->
    $(this).parents("form:first").submit()



    def update
    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|
    format.js{
    @project = Project.find(params[:id])
    @main_hours = main_hours_sum(@project.id)

    }
    end
    end






    Am 20.11.2012 um 13:22 schrieb Jim Ruther Nill <jvnill@gmail.com>:


    On Tue, Nov 20, 2012 at 7:48 PM, Werner wrote:
    o.k.
    Now it is like that:

    def update

    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|
    format.js{

    @project = Project.find(params[:id])
    @main_hours = main_hours_sum(@project.id)
    }
    end
    end

    def main_hours_sum(id)
    hours ||= Booking.where(project_id: id).sum("hour")
    end


    update.js.erb

    alert('<%= @main_hours %>')

    The alert pops up and shows the correct amount of 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.

    If you can show us the code of your edit template, I can help you with the javascript
    to update the total number of hours.


    Greetings



    Am Dienstag, 20. November 2012 11:04:53 UTC+1 schrieb jim:



    On Tue, Nov 20, 2012 at 5:46 PM, Werner wrote:
    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%>

    You need to move the logic in update.js.erb to the update action. I was looking for
    the edit template. I'd like to see how you use the @main_hours variable. What I'm thinking
    is this on this update action and erb.

    def update
    @project = ... #fetch project here

    # move your logic in the view here
    # there's something missing here :D
    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|
    format.html
    format.js { @main_hours = main_hours_sum(@project.id) }
    end
    end

    # update.js.erb
    # use @main_hours to update whatever you need to update on the view

    alert('<%= @main_hours %>')







    Am Dienstag, 20. November 2012 09:59:58 UTC+1 schrieb jim:

    Hi!

    On Tue, Nov 20, 2012 at 4:53 PM, Werner wrote:
    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.

    Can you paste in part of the edit template where you use the result of this query?

    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..?

    Can you also paste your edit and update actions so we can work on the code
    level.


    Thanks for sharing..





    Am Montag, 19. November 2012 15:30:42 UTC+1 schrieb jim:



    On Mon, Nov 19, 2012 at 10:25 PM, Werner wrote:
    On my edit page I can update values using ajax.

    In my edit action I also have something like: Model.where(model_id: id).sum("attribute")
    As the edit action is not executed anymore, I dont get a proper result after I add some new value, have to reload the page.

    How is the best way to actualize the sum after edit.. ?

    Are you updating the values by calling $.ajax or just passing in remote: true on your forms?

    If you use $.ajax, I suggest that you pass in the sum as json which $.ajax can process. If you're
    using remote: true, you can create an update.js.erb or update.js.haml which will be rendered
    after you update.


    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.





    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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/-/GktAGfGYQm4J.

    For more options, visit https://groups.google.com/groups/opt_out.





    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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/-/aGQY2mvKhoUJ.

    For more options, visit https://groups.google.com/groups/opt_out.





    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Uww8jzoTzJcJ.

    For more options, visit https://groups.google.com/groups/opt_out.





    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    Werner Laude
    webagentur.laude@gmail.com



    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jim Ruther Nill at Nov 20, 2012 at 12:55 pm

    On Tue, Nov 20, 2012 at 8:45 PM, Werner Laude wrote:

    here...is the essential

    def edit
    @booking = Booking.new

    @project = Project.find(params[:id])
    @partprojects = Project.find_all_by_parent_id(@project.id)

    @bookings = Booking.zwischen(start, ende)

    @main_hours = main_hours_sum(@project.id)
    @part_hours = part_hours_sum(@partprojects.id)
    @all_hours = @main_hours + @part_hours
    end

    form
    <%= simple_form_for @booking, :url => booking_path, :remote => true,
    :method => :put do %>
    <% @bookings.each do |booking|%>

    <%= fields_for "booking[]", booking do |f|%>
    <%= f.text_field :hour, :class => 'submittable' %>
    <%= hidden_field_tag "booking_ids[]", booking.id %>
    <% end %>

    <% end %>

    coffee
    $(".submittable").live "change", ->
    $(this).parents("form:first").submit()



    def update
    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|
    format.js{
    @project = Project.find(params[:id])
    @main_hours = main_hours_sum(@project.id)

    }
    end
    end
    Ok. sorry but now I'm confused. Where are you using @main_hours,
    @part_hours and @all_hours?
    I need the part of the template that uses these variables.






    Am 20.11.2012 um 13:22 schrieb Jim Ruther Nill <jvnill@gmail.com>:



    On Tue, Nov 20, 2012 at 7:48 PM, Werner wrote:

    o.k.
    Now it is like that:

    def update

    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|
    format.js{

    @project = Project.find(params[:id])
    @main_hours = main_hours_sum(@project.id)
    }
    end
    end

    def main_hours_sum(id)
    hours ||= Booking.where(project_id: id).sum("hour")
    end


    update.js.erb

    alert('<%= @main_hours %>')

    The alert pops up and shows the correct amount of 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.
    If you can show us the code of your edit template, I can help you with the
    javascript
    to update the total number of hours.

    Greetings



    Am Dienstag, 20. November 2012 11:04:53 UTC+1 schrieb jim:


    On Tue, Nov 20, 2012 at 5:46 PM, Werner wrote:

    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%>
    You need to move the logic in update.js.erb to the update action. I was
    looking for
    the edit template. I'd like to see how you use the @main_hours
    variable. What I'm thinking
    is this on this update action and erb.

    def update
    @project = ... #fetch project here

    # move your logic in the view here
    # there's something missing here :D
    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|
    format.html
    format.js { @main_hours = main_hours_sum(@project.id) }
    end
    end

    # update.js.erb
    # use @main_hours to update whatever you need to update on the view

    alert('<%= @main_hours %>')






    Am Dienstag, 20. November 2012 09:59:58 UTC+1 schrieb jim:

    Hi!
    On Tue, Nov 20, 2012 at 4:53 PM, Werner wrote:

    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.
    Can you paste in part of the edit template where you use the result of
    this query?

    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..?
    Can you also paste your edit and update actions so we can work on the
    code
    level.

    Thanks for sharing..



    Am Montag, 19. November 2012 15:30:42 UTC+1 schrieb jim:



    On Mon, Nov 19, 2012 at 10:25 PM, Werner <webagent...@googlemail.**
    com> wrote:
    On my edit page I can update values using ajax.

    In my edit action I also have something like: Model.where(model_id:
    id).sum("attribute")
    As the edit action is not executed anymore, I dont get a proper
    result after I add some new value, have to reload the page.

    How is the best way to actualize the sum after edit.. ?
    Are you updating the values by calling $.ajax or just passing in
    remote: true on your forms?

    If you use $.ajax, I suggest that you pass in the sum as json which
    $.ajax can process. If you're
    using remote: true, you can create an update.js.erb or
    update.js.haml which will be rendered
    after you update.

    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/**ms****g/rubyonrails-talk/-/**
    RHAW38e5g****OwJ<https://groups.google.com/d/msg/rubyonrails-talk/-/RHAW38e5gOwJ>
    .
    For more options, visit https://groups.google.com/**grou****
    ps/opt_out <https://groups.google.com/groups/opt_out>.



    --
    ------------------------------******------------------------------**
    ****-
    visit my blog at http://jimlabs.heroku.com
    --
    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/
    **ms**g/rubyonrails-talk/-/**GktAGfGYQ**m4J<https://groups.google.com/d/msg/rubyonrails-talk/-/GktAGfGYQm4J>
    .

    For more options, visit https://groups.google.com/**grou**ps/opt_out<https://groups.google.com/groups/opt_out>
    .



    --
    ------------------------------****------------------------------****-
    visit my blog at http://jimlabs.heroku.com
    --
    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/-/**aGQY2mvKhoUJ<https://groups.google.com/d/msg/rubyonrails-talk/-/aGQY2mvKhoUJ>
    .

    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .



    --
    ------------------------------**------------------------------**-
    visit my blog at http://jimlabs.heroku.com
    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msg/rubyonrails-talk/-/Uww8jzoTzJcJ.

    For more options, visit https://groups.google.com/groups/opt_out.



    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.




    Werner Laude
    webagentur.laude@gmail.com



    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.



    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Werner Laude at Nov 20, 2012 at 1:10 pm
    Am 20.11.2012 um 13:55 schrieb Jim Ruther Nill <jvnill@gmail.com>:

    I try to explain..

    I have this edit form where I can edit hours
    On 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.





    On Tue, Nov 20, 2012 at 8:45 PM, Werner Laude wrote:
    here...is the essential

    def edit
    @booking = Booking.new

    @project = Project.find(params[:id])
    @partprojects = Project.find_all_by_parent_id(@project.id)

    @bookings = Booking.zwischen(start, ende)

    @main_hours = main_hours_sum(@project.id)
    @part_hours = part_hours_sum(@partprojects.id)
    @all_hours = @main_hours + @part_hours
    end

    form
    <%= simple_form_for @booking, :url => booking_path, :remote => true, :method => :put do %>
    <% @bookings.each do |booking|%>

    <%= fields_for "booking[]", booking do |f|%>
    <%= f.text_field :hour, :class => 'submittable' %>
    <%= hidden_field_tag "booking_ids[]", booking.id %>
    <% end %>

    <% end %>

    coffee
    $(".submittable").live "change", ->
    $(this).parents("form:first").submit()



    def update
    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|
    format.js{
    @project = Project.find(params[:id])
    @main_hours = main_hours_sum(@project.id)

    }
    end
    end

    Ok. sorry but now I'm confused. Where are you using @main_hours, @part_hours and @all_hours?
    I need the part of the template that uses these variables.







    Am 20.11.2012 um 13:22 schrieb Jim Ruther Nill <jvnill@gmail.com>:


    On Tue, Nov 20, 2012 at 7:48 PM, Werner wrote:
    o.k.
    Now it is like that:

    def update

    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|
    format.js{

    @project = Project.find(params[:id])
    @main_hours = main_hours_sum(@project.id)
    }
    end
    end

    def main_hours_sum(id)
    hours ||= Booking.where(project_id: id).sum("hour")
    end


    update.js.erb

    alert('<%= @main_hours %>')

    The alert pops up and shows the correct amount of 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.

    If you can show us the code of your edit template, I can help you with the javascript
    to update the total number of hours.


    Greetings



    Am Dienstag, 20. November 2012 11:04:53 UTC+1 schrieb jim:



    On Tue, Nov 20, 2012 at 5:46 PM, Werner wrote:
    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%>

    You need to move the logic in update.js.erb to the update action. I was looking for
    the edit template. I'd like to see how you use the @main_hours variable. What I'm thinking
    is this on this update action and erb.

    def update
    @project = ... #fetch project here

    # move your logic in the view here
    # there's something missing here :D
    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|
    format.html
    format.js { @main_hours = main_hours_sum(@project.id) }
    end
    end

    # update.js.erb
    # use @main_hours to update whatever you need to update on the view

    alert('<%= @main_hours %>')







    Am Dienstag, 20. November 2012 09:59:58 UTC+1 schrieb jim:

    Hi!

    On Tue, Nov 20, 2012 at 4:53 PM, Werner wrote:
    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.

    Can you paste in part of the edit template where you use the result of this query?

    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..?

    Can you also paste your edit and update actions so we can work on the code
    level.


    Thanks for sharing..





    Am Montag, 19. November 2012 15:30:42 UTC+1 schrieb jim:



    On Mon, Nov 19, 2012 at 10:25 PM, Werner wrote:
    On my edit page I can update values using ajax.

    In my edit action I also have something like: Model.where(model_id: id).sum("attribute")
    As the edit action is not executed anymore, I dont get a proper result after I add some new value, have to reload the page.

    How is the best way to actualize the sum after edit.. ?

    Are you updating the values by calling $.ajax or just passing in remote: true on your forms?

    If you use $.ajax, I suggest that you pass in the sum as json which $.ajax can process. If you're
    using remote: true, you can create an update.js.erb or update.js.haml which will be rendered
    after you update.


    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.





    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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/-/GktAGfGYQm4J.

    For more options, visit https://groups.google.com/groups/opt_out.





    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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/-/aGQY2mvKhoUJ.

    For more options, visit https://groups.google.com/groups/opt_out.





    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Uww8jzoTzJcJ.

    For more options, visit https://groups.google.com/groups/opt_out.





    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    Werner Laude
    webagentur.laude@gmail.com




    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.





    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    Werner Laude
    webagentur.laude@gmail.com



    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jim Ruther Nill at Nov 20, 2012 at 1:20 pm

    On Tue, Nov 20, 2012 at 9:10 PM, Werner Laude wrote:
    Am 20.11.2012 um 13:55 schrieb Jim Ruther Nill <jvnill@gmail.com>:

    I try to explain..

    I have this edit form where I can edit hours
    On 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.
    Ok. It's clearer now but you still need to show the html code above the
    form where you use
    @main_hours, @part_hours and @all_hours. If you some sort of code before
    your form like
    this one

    <div id='main-hours'>
    <label>Main Hours</label>
    <span><%= @main_hours %>
    </div>

    you can add this line in update.js.erb to update the main hours

    $('#main-hours span').text('<%= @main_hours %>');

    Good luck!








    On Tue, Nov 20, 2012 at 8:45 PM, Werner Laude <
    webagentur.laude@googlemail.com> wrote:
    here...is the essential

    def edit
    @booking = Booking.new

    @project = Project.find(params[:id])
    @partprojects = Project.find_all_by_parent_id(@project.id)

    @bookings = Booking.zwischen(start, ende)

    @main_hours = main_hours_sum(@project.id)
    @part_hours = part_hours_sum(@partprojects.id)
    @all_hours = @main_hours + @part_hours
    end

    form
    <%= simple_form_for @booking, :url => booking_path, :remote => true,
    :method => :put do %>
    <% @bookings.each do |booking|%>

    <%= fields_for "booking[]", booking do |f|%>
    <%= f.text_field :hour, :class => 'submittable' %>
    <%= hidden_field_tag "booking_ids[]", booking.id %>
    <% end %>

    <% end %>

    coffee
    $(".submittable").live "change", ->
    $(this).parents("form:first").submit()



    def update
    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|
    format.js{
    @project = Project.find(params[:id])
    @main_hours = main_hours_sum(@project.id)

    }
    end
    end
    Ok. sorry but now I'm confused. Where are you using @main_hours,
    @part_hours and @all_hours?
    I need the part of the template that uses these variables.






    Am 20.11.2012 um 13:22 schrieb Jim Ruther Nill <jvnill@gmail.com>:



    On Tue, Nov 20, 2012 at 7:48 PM, Werner wrote:

    o.k.
    Now it is like that:

    def update

    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|
    format.js{

    @project = Project.find(params[:id])
    @main_hours = main_hours_sum(@project.id)
    }
    end
    end

    def main_hours_sum(id)
    hours ||= Booking.where(project_id: id).sum("hour")
    end


    update.js.erb

    alert('<%= @main_hours %>')

    The alert pops up and shows the correct amount of 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.
    If you can show us the code of your edit template, I can help you with
    the javascript
    to update the total number of hours.

    Greetings



    Am Dienstag, 20. November 2012 11:04:53 UTC+1 schrieb jim:


    On Tue, Nov 20, 2012 at 5:46 PM, Werner wrote:

    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%>
    You need to move the logic in update.js.erb to the update action. I
    was looking for
    the edit template. I'd like to see how you use the @main_hours
    variable. What I'm thinking
    is this on this update action and erb.

    def update
    @project = ... #fetch project here

    # move your logic in the view here
    # there's something missing here :D
    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|
    format.html
    format.js { @main_hours = main_hours_sum(@project.id) }
    end
    end

    # update.js.erb
    # use @main_hours to update whatever you need to update on the view

    alert('<%= @main_hours %>')






    Am Dienstag, 20. November 2012 09:59:58 UTC+1 schrieb jim:

    Hi!

    On Tue, Nov 20, 2012 at 4:53 PM, Werner <webagent...@googlemail.**com
    wrote:
    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.
    Can you paste in part of the edit template where you use the result
    of this query?

    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..?
    Can you also paste your edit and update actions so we can work on the
    code
    level.

    Thanks for sharing..



    Am Montag, 19. November 2012 15:30:42 UTC+1 schrieb jim:



    On Mon, Nov 19, 2012 at 10:25 PM, Werner <webagent...@googlemail.**
    com> wrote:
    On my edit page I can update values using ajax.

    In my edit action I also have something like:
    Model.where(model_id: id).sum("attribute")
    As the edit action is not executed anymore, I dont get a proper
    result after I add some new value, have to reload the page.

    How is the best way to actualize the sum after edit.. ?
    Are you updating the values by calling $.ajax or just passing in
    remote: true on your forms?

    If you use $.ajax, I suggest that you pass in the sum as json which
    $.ajax can process. If you're
    using remote: true, you can create an update.js.erb or
    update.js.haml which will be rendered
    after you update.

    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/**ms****g/rubyonrails-talk/-/**
    RHAW38e5g****OwJ<https://groups.google.com/d/msg/rubyonrails-talk/-/RHAW38e5gOwJ>
    .
    For more options, visit https://groups.google.com/**grou****
    ps/opt_out <https://groups.google.com/groups/opt_out>.



    --
    ------------------------------******------------------------------*
    *****-
    visit my blog at http://jimlabs.heroku.com
    --
    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/**ms**g/rubyonrails-talk/-/**GktAGfGYQ**
    m4J<https://groups.google.com/d/msg/rubyonrails-talk/-/GktAGfGYQm4J>
    .

    For more options, visit https://groups.google.com/**grou**ps/opt_out<https://groups.google.com/groups/opt_out>
    .



    --
    ------------------------------****------------------------------****-
    visit my blog at http://jimlabs.heroku.com
    --
    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/-/**aGQY2mvKhoUJ<https://groups.google.com/d/msg/rubyonrails-talk/-/aGQY2mvKhoUJ>
    .

    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .



    --
    ------------------------------**------------------------------**-
    visit my blog at http://jimlabs.heroku.com
    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msg/rubyonrails-talk/-/Uww8jzoTzJcJ.

    For more options, visit https://groups.google.com/groups/opt_out.



    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.




    Werner Laude
    webagentur.laude@gmail.com




    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.



    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.




    Werner Laude
    webagentur.laude@gmail.com



    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.



    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Werner Laude at Nov 20, 2012 at 1:31 pm

    Am 20.11.2012 um 14:19 schrieb Jim Ruther Nill <jvnill@gmail.com>:

    $('#main-hours span').text('<%= @main_hours %>');
    perfect.. thanks a lot..
    Now I get the idea..



    Werner Laude
    webagentur.laude@gmail.com



    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jim Ruther Nill at Nov 20, 2012 at 1:37 pm

    On Tue, Nov 20, 2012 at 9:31 PM, Werner Laude wrote:
    Am 20.11.2012 um 14:19 schrieb Jim Ruther Nill <jvnill@gmail.com>:

    $('#main-hours span').text('<%= @main_hours %>');


    perfect.. thanks a lot..
    Now I get the idea..
    Cheers! At least we nail that one :)


    Werner Laude
    webagentur.laude@gmail.com



    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.



    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Werner Laude at Nov 20, 2012 at 1:56 pm
    yes. thanks a lot..

    The one more thing...

    I try to complete that

    respond_to do |format|
    format.js{
    @project = Project.find(params[:id])
    @main_hours = main_hours_sum(@project.id)
    @part_hours = part_hours_sum(@partprojects)
    @all_hours = @main_hours + @part_hours
    }
    end

    $('#main-hours span').text('<%= @main_hours %>');
    $('#all-hours span').text('<%= @all_hours %>');


    <div id="main-hours"><span><%= @main_hours %></span> h</div>
    <div id="all-hours"><span><%= @all_hours %></span> h</div>

    But then noting is working.. mhhh..



    Am 20.11.2012 um 14:37 schrieb Jim Ruther Nill <jvnill@gmail.com>:


    On Tue, Nov 20, 2012 at 9:31 PM, Werner Laude wrote:

    Am 20.11.2012 um 14:19 schrieb Jim Ruther Nill <jvnill@gmail.com>:
    $('#main-hours span').text('<%= @main_hours %>');
    perfect.. thanks a lot..
    Now I get the idea..


    Cheers! At least we nail that one :)



    Werner Laude
    webagentur.laude@gmail.com




    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.





    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    Werner Laude
    webagentur.laude@gmail.com



    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 19, '12 at 2:30p
activeNov 20, '12 at 1:56p
posts15
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Werner Laude: 8 posts Jim Ruther Nill: 7 posts

People

Translate

site design / logo © 2021 Grokbase