Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to call a custom action? #1

Closed
Shigawire opened this issue Sep 16, 2015 · 5 comments
Closed

How to call a custom action? #1

Shigawire opened this issue Sep 16, 2015 · 5 comments

Comments

@Shigawire
Copy link

In your backend code you provided the possibility to call custom actions additionally to the RESTful ones.

Let's assume I have the following code in my controller:

def start
 broadcast do
  @server = Server.find(params[:id]).start()
 end
end

How would I call the start action from this client side?

Good work by the way! I really enjoy not having to take care of the data being pulled into the frontend.

@dchacke
Copy link
Owner

dchacke commented Sep 28, 2015

What's your route to that action?

@Shigawire
Copy link
Author

Like this

          servers_new GET      /servers/new(.:format)                              servers#new
       create_servers GET      /servers/create(.:format)                           servers#create
        update_server GET      /servers/:id/update(.:format)                       servers#update
       destroy_server GET      /servers/:id/destroy(.:format)                      servers#destroy
         start_server GET      /servers/:id/start(.:format)                        servers#start
          stop_server GET      /servers/:id/stop(.:format)                         servers#stop
              servers GET      /servers(.:format)                                  servers#index
               server GET      /servers/:id(.:format)                              servers#show

Edit: I've digged through the Javascript Code a bit, but could not find anything about anything other than CRUD.. The minified script made it a bit hard to inspect the code.

@dchacke
Copy link
Owner

dchacke commented Sep 28, 2015

I don't think there's currently a method baked into the Angular package. You can always instantiate your own socket though:

var socket = new WebSocket('ws://localhost:3000/servers/1/start');
socket.onopen = function (data) { console.log('opened:', data); }
socket.onmessage = function (data) { console.log('message:', data); }

Or something similar. Entangled should take care of the rest in the backend though. If it doesn't, let me know.

@Shigawire
Copy link
Author

Well, I thought so.
Thanks for clearing that up!

@dchacke
Copy link
Owner

dchacke commented Sep 28, 2015

Here's the un-minified source if you're interested.

@dchacke dchacke closed this as completed Sep 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants