2014-12-17 5 views
5

그래서이 보석을 사용하여 모바일 앱의 푸시 알림에 rpush를 사용하려고했습니다 : https://github.com/rpush/rpush. 나는 sinatra 프레임 워크를 사용하고 있습니다. 하지만 필자는이 파일을 맨 위에 "rpush"해야한다고 썼다. 루비를 경험 한 사람이 나를 도울 수 있습니까? 나는 루비가 처음이에요. 제발 저를 참아주십시오. 여기에 내 코드NameError : 초기화되지 않은 상수 Rpush :: Gcm 내 모바일 앱에 rpush를 사용하려고합니다. 하지만이 오류가 계속 발생

require 'rpush' 

Module Notifier 

def rpush_client 
app = Rpush::Gcm::App.new 
app.name = "App-Name" 
app.auth_key = "XXXXXXXXXXXXXXX" 
app.connections = 1 
app.save! 
end 


def notify(user_id,alert) 
    rpush_client 
    session = db_find_one('dbname.sessions',{user_id: user_id}) 
    if session.present? 
    device = session['devices'].first 
    token = device['device_token'] 
    n = Rpush::Gcm::Notification.new 
    n.app = Rpush::Gcm::App.find_by_name("App-Name") 
    n.registration_ids = ["token", token] 
    n.data = { message: alert } 
    n.save! 

    Rpush.push 
    end 
end 

end 

나는 그것의 바보 같은 질문을 알고 있지만 여기에 대해 찾고 피곤합니다.

답변

0

Sinatra와 함께 번들러를 사용하고 있습니까? 그렇다면 Rpush를 명시 적으로 요구하지 않아도됩니다. 참조 : http://bundler.io/sinatra.html

+0

"require 'rpush'"를 제거하면 초기화되지 않은 상수 Rpush 오류가 발생합니다. 나는 "rpush/gcm"을 요구하는 것과 같은 것을 넣어야한다고 생각한다. 그러나 나는 그것을 시도했다, 그것은 작동하지 않는다. – Renegade