1

x-editable を使用して、ユーザーが自分自身を別のモデルに関連付けることができるようにします。スタイルは、ユーザーが関連付けられているモデルのタイプに基づいて変化します。

現在は動作していますが、css クラスはページを更新した後にのみ変更されます。

x-editable が新しい値を保存した後、css クラスをリセットするにはどうすればよいですか?

これは私の入力がどのように見えるかです->

== editable user, :heat_id, url: admin_user_path(user), type: "select", value: (user.heat.level if user.heat), source: Heat.all.map{ | heat | {value: heat.id, text: heat.level} }, class: "#{user.heat.badge if user.heat}"

基本的に再申請する必要がある

class: "#{user.heat.badge if user.heat}"

アップデート

x-editable-rails には実際にこれが組み込まれていることがわかりました。解決策は次のように書くことでした ->

== editable user, :heat_id, url: admin_user_path(user), type: "select", value: (user.heat.level if user.heat), source: Heat.all.map{ | heat | {value: heat.id, text: heat.level} }, classes: Hash[Heat.all.map{ | heat | [heat.id, heat.badge]}], class: "#{user.heat.badge if user.heat}"

しかし、 ajaxを使用して保存した後に要素を変更する方法はまだわかりません。

たとえば、私がやりたいことは、保存イベントの後、部分的な「進行状況」を再レンダリングすることです。

どうすればそれを行うことができますか?

4

1 に答える 1

1
$('.profile_editable').on('save', function(e, params) {
    var progress_value = params.response.progress_value
    $('.progress_title').text("Your profile is " + progress_value + "% completed" )
    $('.bar').css('width', progress_value + '%');
});

次に、json 応答で情報を渡します -->

  def update
    @common_app = CommonApp.find(params[:id])
    if @common_app.update_attributes(common_app_params)
      respond_to do |format|
        format.html { render :action => "show" }
        format.json { render json: {success: true, progress_value: @common_app.user.progress, user_name: @common_app.user.name } }
      end
    else
       render json: {errors: @common_app.errors}, status: 400
    end
  end
于 2014-01-28T07:05:47.420 に答える