Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen I make a change with best_in_place, I want another text value on the page updated
    primarykey
    data
    text
    <h2>EDIT #2</h2> <p>It seems to me I should be able to use javascript to JSON parse whatever <code>respond_with_bip(@buildingTour)</code> returns, because that IS the updated object I need (I need to access the updated value of <code>@buildingTour.monthly</code>). However, when I try to parse it, I'm having no luck. I've read something about respond_with_bip breaking JSONParse, so maybe that is what is happening.</p> <p>If anyone can help me parse @buildingTour to get the monthly attribute (i.e., show me the javascript), it would be greatly appreciated.</p> <h2>EDIT</h2> <p>@MikeKijewski - Just to clarify, my view is a show view, i.e. we are only dealing with a single row. I know the SO article you were referring to was dealing with a table with multiple rows, which was a little trickier. What I don't understand is why the "respond_with_bip" in my controller isn't already returning what I need. Here is my controller:</p> <pre><code> def update @buildingTour = BuildingTour.find(params[:id]) respond_to do |format| if @buildingTour.update_attributes(params[:building_tour]) format.json { respond_with_bip(@buildingTour) } else format.json { respond_with_bip(@buildingTour) } end end end </code></pre> <p>So why can't I use the data returned by "respond_with_bip" to update the field on the page?</p> <p>For now I'm just using <code>location.reload();</code> whenever the two fields in question (sqft and rentalrate) are updated with best_in_place, which then shows the appropriate value for the 3rd field (monthly).</p> <hr> <p>I'm using <code>best_in_place</code> in my rails app (for in-place editing of the values sqft and rate) and it works great with one exception:</p> <p>I have a calculated attribute in my model called <code>monthly</code>. When I change a value with a <code>best_in_place</code>, I need that <code>monthly</code> value recalculated and updated on the page.</p> <p>Here is the code for <code>monthly</code> in my model:</p> <pre><code> def monthly if sqft &amp;&amp; rate monthly = (sqft * rate) / 12 end end </code></pre> <p>Here is the code snippet from my view (this is the text I want updated - it is inside a span with id "rental-details"):</p> <pre><code>&lt;strong&gt;&lt;%= number_to_currency(@buildingTour.monthly, :precision =&gt; 0) %&gt;&lt;/strong&gt; </code></pre> <p>Here is the javascript where I recognize when a <code>best_in_place</code> change is made and then in theory update the value above:</p> <pre><code>$('.best_in_place').change(function() { $.ajax({ success: function() { $("#rental-details strong").text('&lt;%= number_to_currency(@buildingTour.monthly, :precision =&gt; 0) %&gt;'); } }); }); </code></pre> <p>So the code all "works" without errors . . . except it is pulling the old value of monthly. I tested this by removing <code>number_to_currency</code> from the JavaScript, and sure enough when I change one of the other values it removes the currency formatting from the value on the page (so I know the JavaScript is being triggered and updating the text).</p> <p>I thought maybe the JavaScript was just firing too quickly (and the database had not been updated with the new values for sqft and rate yet), but I tried changing the values of sqft and rate several times and the monthly value never updated.</p> <p>So anyway does the <code>&lt;%= number_to_currency(@buildingTour.monthly, :precision =&gt; 0) %&gt;</code> part of the JavaScript only get called once when the page loads or something? If so, how do you force it to query <code>monthly</code> every time?</p> <p>One thing to point out ... <code>monthly</code> is not a column in the <code>building_tours</code> table, I just calculate it on the fly.</p> <p>Thanks for any insight into this issue. I've googled and stackoverflowed the heck out of this and they all make me feel like my current code should be working.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload