Code Monkey home page Code Monkey logo

Comments (5)

afeld avatar afeld commented on August 23, 2024

Can you give a bit more context? If you can paste your view and controller code I can probably be more helpful. Also, is the request returning with a status of 200 (you can check this in your Rails log, and/or with the Firebug Net tab (or equivalent)).

from jeditable-rails.

marccantwell avatar marccantwell commented on August 23, 2024

Code is for a polymorphic address object. On submit works, the data is submitted to the database and upon browser refresh the updated information is displayed. However, it doesn't refresh/update the divs that have been updated upon submit. No status 200.

----View----
<%= div_for address do %>

Address:


<%= editable_field address, :street, :cancel => 'Cancel', :submit => 'Submit', :indicator => '"<img src="/images/loader.gif>"', :tooltip => 'Click to edit...' %>


<%= editable_field address, :city, :onblur => 'submit' %>


<%= editable_field address, :state %>


<%= editable_field address, :zip %>


<%= editable_field address, :type %>

<%= link_to 'Delete',address, :method => :delete, :class => "delete", :remote => true  %>

<% end %>

---Controller---
class AddressesController < ApplicationController
def create
@address = Address.new(params[:address])

if @address.save
  flash[:notice] = "Thanks for your address!"
else
  flash[:alert] = "Your addresses might have some errors, please check and try again."
end

respond_to do |format|
  format.html { redirect_to @address.addressable }
  format.js
end

end

PUT /notes/1

PUT /notes/1.xml

def update
@address = Address.find(params[:id])

  if @address.update_attributes(params[:address])
    flash[:notice] = "Address Updated!"
  else
    flash[:alert] = "Your addresses might have some errors, please check and try again."
  end
respond_to do |format|
    format.html
    format.js
end

end

def destroy
@address = Address.find(params[:id])
@address.destroy

respond_to do |format|
  format.html { redirect_to @address.addressable }
  format.js 
end

end
end

from jeditable-rails.

afeld avatar afeld commented on August 23, 2024

So I think the problem is that the new value is not being returned from the update action in your controller - jeditable uses the response body as the new value for the field. I clearly failed to document this. This is a snippet of my respond_to block for the Resource model (see the full controller here):

format.html {
  if request.xhr?
    render :text => params[:resource].values.first
  else
    redirect_to(@resource, :notice => 'Resource was successfully updated.')
  end
}

Now realizing it really needs a helper method or something provided by the gem to make it cleaner... I'm open to suggestions about how to do this, but will take a stab at it in the next few days and try to get it out asap. Thanks for putting this through it's paces!

from jeditable-rails.

marccantwell avatar marccantwell commented on August 23, 2024

Thank yo uso much for all your work on this. I think it is a great gem. I'll think on the helper method as I continue to work with it. Thanks again for your quick response.

from jeditable-rails.

troya2 avatar troya2 commented on August 23, 2024

I added the following helper method to application_controller.rb

def respond_to_jeditable resource
  if request.xhr?
    render :text => params[resource].values.first
    true
  else
    false
  end
end

And use it in my controllers this way:

def update
  @job.update_attributes(params[:job])

  respond_to_jeditable(:job) || respond_with(@job)
end

from jeditable-rails.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.