I have two apps AppA and AppB which point to same database, but different tables, now I want to embed AppB into AppA, when service of AppA starts up, I could access AppB's page by submenu of AppA.
so what kind of technique I could utilize to do that?
http://railscasts.com/episodes/277-mountable-engines
or
Differences between railties and engines in Ruby On Rails 3
They are helpful.
However, our case looks mostly like this, Combining two Rails applications into one
Related
For a mobile application project I need a REST API that I'm going to do with FOSRestBundle and I need a backend website to manage the database (CRUD)
How can I do to have only one instance of each entity? should I create 2 projects or 2 Bundles?
It is better you create 2 bundles. and create all entity In one of them.
For example, create AdminBundle and AppBundle .use AppBundle for frontend .and AdminBundle for Backend and API.All entity creates in AdminBundle.
Even you can manage events or requests by building different controls. for example, you can have a bundle and create ApiController, FrontController,...
I think making two projects is the worst solution
I can say what i will do in this case.
Create 1 RESTFUL API project without any frontend part.
Create SPA (React.js, Vue.js, Angular) website for admin
Create SPA frontend website for users.
You can take a look at https://api-platform.com/ to get more understanding how it should be.
UPD.: If you think about splitting API project to microservice and can not make choice if you need it or not I can help you. You need it if you have many teams who need to deliver tasks in parallel. If you work alone or with small team you can work with monolith.
The project I'm currently working on is split up in an admin console and the normal frontend.
Both front and backend are in the same Laravel instance.
In the frontend I'm trying to create a user login system that works exclusively for the frontend. It uses a different table and model and it has different relations as oposed to the User model for the admin.
What I can't figure out is a way to use the Laravel Auth class for both systems. Logically Auth uses one single config file, and more to the point, one session name.
One solution that has been brought forward is not to use a different table and model and use some form of acl for the distinction. But I don't like the idea of mixing frontend and backend in this way. Especially because it would mean I'd suddenly have to give the admin User model all the fields and relations previously unique to the frontend user.
It just doesn't seem the right way to do things. I could switch to a different authentication system or seperate the admin into a package with its own configs but the scope of the project doesn't allow for such timeconsuming changes.
I'd welcome any idea's you could provide.
This is a problem that I encountered recently too. The whole separate environment wasn't very easy, especially if you already have development and production environments.
I did however spend some time creating a package to solve this problem, which you can find at https://github.com/ollieread/multiauth. The package itself is essentially a factory class for Auth, that allows you to use multiple instances of it, so you access it like so:
Auth::admin()->check();
Auth::user()->check();
Auth::whatever()->check();
I hope the package helps you or anyone else looking for this approach.
I'm not sure, but maybe it's useful. Why not try to create to separate environment for admin. And then you will have something like app/config/admin/session.php and app/config/session.php for production(which is the default environment).
You can see here how to setup environments http://andrewelkins.com/programming/php/how-to-set-laravel-4-environments/
But as I said it's just an idea, I'm not quite sure of it :)
Sounds like you should consider splitting the app into two codebases if the different user entities rarely or never need to see the same interface. They would still query the same database obviously.
Not only will this solve your auth issues, but also make maintaining the code a heck of a lot easier. For example, while pushing updates to the admin console you would only need to put that app in maintenance mode while keeping the (presumably) more critical frontend up and running.
As a preface to this question: I am brand new to Rails development (and web-development in general), and some of my concerns may be unfounded, so any feedback would be very helpful.
I am attempting to make a Rails application that plugs into a RESTful API. I have been trying to determine the best way to go about this, and from what I understand, its narrowed down to making my own model from the ground up, utilizing ActiveModel, or utilizing ActiveResource.
It is unclear to me the advantages/disadvantages of each, and to be frank, I do not yet fully understand the difference between ActiveModel and ActiveResource. Can somebody provide me with insight regarding these three options and what makes the most 'sense' in a ror context? Thanks!
The best answer wouldn't just say "Use ActiveModel", or "Use ActiveResource" with instructions on doing so, however that would be helpful as well. I would really appreciate an answer explaining why I should use that thing, etc.
A few constraints I am dealing with are that I need to be using a key when I call the API, and a good number of the API calls will contain additional parameters.
So the key to choosing which package to use here is whether:
You are RETRIEVING data from the web API and want to
store/manipulate on YOUR server, or
You are MANIPULATING data via the web API and don't intend on storing anything on your server.
If #1, you'll need ActiveRecord, as it's Rails' package for manipulation and storage of data on your Postgres/MySQL/etc database.
If #2, you can use ActiveResource exclusively, which will let you retrieve data from the web API, work with it at runtime, and then make changes by posting back to the web API.
Many applications though, will often use both of these packages. ActiveResource to grab data very easily, and then applying it to ActiveRecord models (like User, or Location, etc) which you can use locally without having to grab data from the API over and over again.
To give you an example, for a service I was working on I grabbed Geolocation data from a public source (looking up coordinates for zipcodes), I then saved that data to local Location objects using ActiveRecord so I could look them up repeatedly without the delay of the Web API call. (if you're smart, you'll refresh this data from the web API from time to time)
Determining whether ActiveResource will work for you
Do the service requests conform to the documentation protocol? Look at the Expects a response of block in the Find method, for example. If so, you might be good to go without extra work.
Note: The documentation is a little out of sync with the changelog — as of Rails 3.1:
The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. eg.
Also, ActiveResource has been removed entirely from the Rails 4.0 branch, so if you're looking forward to starting a new rails application and want the latest and greatest, this isn't an option at all — but all hope is not lost, there are plenty of gems that make interacting with RESTful interfaces simpler, like Faraday (full disclosure: I have not used faraday myself so can really comment on its efficacy, but I located it here, and there are a number of other options.
Note (from the same link above): Active Resource is built on a standard XML format for requesting and submitting resources over HTTP. It mirrors the RESTful routing built into Action Controller but will also work with any other REST service that properly implements the protocol. REST uses HTTP, but unlike “typical” web applications, it makes use of all the verbs available in the HTTP specification.
If the answer to the above is no (it does not conform) you'll need to write a wrapper class, see Facebooker for an example of how this is done in an actively maintained gem.
References:
Great tutorial on ActiveResource
Getting started with ActiveRecord
Keep in mind if you're just starting web development, you'll need to understand database and model basics too — you have your work cut out for you. :)
I will give it a try, and hopefully others will come and correct (or add) to it, so a better picture will exist ...
I see the following main differences between the two:
ActiceResource provides an interface to a resource that is (normally) accessible remotely by a (Rails) RESTful API. It is not stored kept locally, but read, updated, created and deleted by the API only. As Ryan Bates states it: "ActiveResource allows you to easily communicate between multiple Rails applications."
ActiveRecord (or nowadays ActiveModel) stores its record (or model) in a database locally, and allows others to access it remotely by a web interface for
Showing pages
Returning JSON maps or
Returning XML structures
Advantages and Disadvantages
To use ActiveResource, you have to check that your local Rails app can speak to the remote application, so that the RESTful API is compatible.
If both options are free to choose, here are some arguments:
ActiveResource will normally more expensive (calling a remote system costs at least more time) than ActiveModel.
ActiveModel will cost your own resources (setup of database at least), but this is normally not a burden.
So at the end, it depends on if you want to store something (ActiveModel) or only retrieve something (ActiveResource), which means you will use ActiveResource and (perhaps) ActiveMiodel.
I've built an app using Ruby On Rails 3, and now, as I've got more than one app that use the same models, I would like to build a third app for the model's logic, and call it from each app, in order to avoid repeating code across apps, etc.
To do that, I've thought about building a Rails app, and returning/receiving information through XML, and so far I've got no issues...until I've started thinking about ActiveRecod works directly with the database, and I no longer want that...now I want my app to call the service, and then communicate with the DB from there.
So, the question is: how can I move all the model's logic to a webservice without losing ActiveRecord magic in controllers, helpers, etc?
Thanks,
Brian
You can access the service via ActiveResource models - http://api.rubyonrails.org/classes/ActiveResource/Base.html. They mimic much of the basic ActiveRecord functionality.
I wanted to understand how rails console interacts directly with the model classes without getting routed via controllers.
And if the same mechanism can be used for integrating rails applications which are within a single enterprise.
I understand filters e.g. authentication filter will not be applied hence it may not be the right way to integrate applications but then a question raises as to what's the right place to code such logic which filter requests when there is more than one way of accessing.