我的喜欢按钮上的计数器跨度没有用ajax更新

时间:2016-05-02 17:04:35

标签: javascript ruby-on-rails ajax

我已经按照SO(this questionthis question)上的其他问题提出的答案,但由于某种原因,我无法让我的按钮计数器与ajax正常工作。我的计数器只有在刷新后才会更改,感谢任何帮助!

#!/usr/local/env/project_django18/bin/python
import os
import sys
sys.path.append('/usr/local/env/project/')
import project

os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
activate_this = os.path.expanduser("/usr/local/env/project_django18/bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
<Button
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="register"
    android:id="@+id/welcome_register"
    android:background="@android:color/holo_green_dark"
    android:textColor="#ffffff"
    android:textSize="25sp"
    />

#upvote.coffee

package il.co.smartchip.hobby;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class LoginActivity extends AppCompatActivity {

private Button myButton;
private Activity thisActivity=this;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    getSupportActionBar().hide();
    myButton=(Button)findViewById(R.id.welcome_register);
    myButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(thisActivity, RegisterActivity.class);
            startActivity(intent);
        }
    });
}}

#index.html.erb

meals_controller.rb

def upvote  
    @meal.upvote_from current_user 
      if request.xhr?
        render json: { count: @meal.get_upvotes.size, id: params[:id] }
      else
        redirect_to meals_path
      end
  end

  def unlike
    @meal.unliked_by current_user 
    redirect_to meals_path
  end

0 个答案:

没有答案