Sending Emails with Rails API & AngularJS - ruby-on-rails

I've been rebuilding a rails site with an Angular front end.
Is there an angular-way to do emails? I was trying to send them through the rails server, but now all my rails url helpers are screwed up by the difference between the angular url routes and the rails API routes. Do I use angular? Do I use rails url helpers somehow? Or do I manually update each route with this gnarly pattern:
Link to Post
Thanks!

Related

Search form on WordPress show results on rails application

I have built our marketing pages on WordPress and I was hoping I could add a search form on the WordPress site and show the results on the Rails application. Could I use Elementor to build a form and on submit that info is sent to the rails application to show the results from the rails DB and the user will now be on the rails application?
Thanks
You're asking about a form that is hosted on a Wordpress instance, which submits to a Rails app. While in general you could set the form action to post to any server, you will have problems doing this with Rails specifically because of the form authenticity_token, which is required by default for Rails forms with POST method.
See ActionController::RequestForgeryProtection
One way to stop Rails from doing this is to disable request forgery protection in your Rails controller:
protect_from_forgery with: :null_session
Another approach could be to build the search form in your Rails app, and embed it in an iFrame on your Wordpress. After the form is submitted in the iframe, you can redirect_to the results from the Rails controller, which will break out of the iframe with a HTTP 302 response that sets the user's browser location to the Rails application's results page.

How to integrate EmberJS incrementally into an rails web app?

we're working on our opensource password manager cryptopus https://github.com/puzzle/cryptopus.
since our last release we integrated emberjs and are updating one component after another from classic rails webapp to emberjs. For now, we used locationType: "hash" to trigger emberjs parts.
one challenge we're facing now is to make sure the URLs are still the same after moving the UI components to emberjs. So we should get rid of "hash"-URLs for emberjs and still be able to call some legacy rails webapp URLs.
is there a way to ignore routes in emberjs and sending the request to the backend? any other ideas to make an incremental integration of emberjs possible? It would be OK if the SPA would be re-initialized after coming back from an class rails webapp URL.
some example routes:
/session/new -> send to rails backend
/teams -> handle by emberjs
/teams/42 -> handle by emberjs
/admin/users -> send to rails backend
it would be also possible to add a prefix for all emberjs handled routes like: /app/teams, /app/teams/42
we found a pretty simple solution for the problem.
in config/environment.js: removed rootURL, locationType: "auto"
configured all required routes in emberjs
created an frontend controller in rails which serves the ember files on first request
so now, some frontend parts of the app run with ember, others still with rails. the ember router doesn't care about URLs that are not configured. Pretty nice solution :)
have a look at https://github.com/puzzle/cryptopus to see the complete solution.

Rails CRUD operations using AJAX

I'm developing a Rails app. I have generated all my resources using the scaffold generator, and now I'm working on javascript, on an AJAX function.
I saw that if I request /entities/1.json, it returns JSON data for the record with id=1, so I was wondering if it's possible to do other CRUD operations the same way with GET/POST http requests using routes like /entities/new.json or so, that is, make an AJAX request sending post data as JSON.
Can you guide me on how to do that?
As you saw, scaffolds generates proper url and code for both HTML and json, so sending a POST to create a resource should work without problems.
You can find more info in the Rails guides about JavaScript and JSON

How to deal with Restful resource when using Angular token auth with Rails

I'm using ng-token-auth on Angular and with devise-token-auth on Rails for authentication which works fine but there are occasionally I need to sent in id of the user or any other resource for show function in Rails resource
When I however request for show on User resource I don't have a way to find out id of the current user before it reaches the server to be sent as part of url in the request.
What is the recommended way to deal with this Restful routes situation when used with token authentication on Rails and Angular?

Rails: how to simulate a form submission from inside a controller method?

I'm working on a Ruby on Rails project where we want to automate some form submissions. How do we simulate posting a form from inside a controller method?
You could follow the POST below to use net/http to do a form post to an external or internal HTTP end point.
Submitting POST data from the controller in rails to another website
or you could use a popular HTTP client or REST client like httparty, wrest, mechanize etc. Look at the list here. https://www.ruby-toolbox.com/projects/rest-client

Resources