Recently, organization leaders deployed a task to develop the user self-service system. This task was completed independently by only one of me-Haha, a wonderful job.
It happened that the landlord was recently confused by the wonderful features of Ruby, so he put it into the arms of Ruby on Rails without hesitation.
However, in the process of system development, the leaders made new instructions to interact with the ruijie Sam system. MB! What should I do? Well, fortunately, there is still jruby which can handle the task. There are not many users in this system, and the performance should not be a problem!
Because I used rails for the first time and was still working with jruby, I encountered some problems, so I should record them. (A microblog I saw at noon today said: If you want to let a person die, let him do jruby on Rails ~~~ Is this suicide ~~~~)
[Rails 4.1, jruby 1.7.5 used by the landlord]
Question 1. How does rails interact with existing databases?
In addition to interacting with WebService, the system also needs to interact with the database, which already exists, therefore, you cannot use rails's convenient "Rails G model". What should you do? After several attempts, I found that the following methods can be used:
1. rails G model modelname
Generate the data model corresponding to the data table. You do not need to specify the column type and name, and the table name and class name do not need to be completely consistent.
2. Add the following code to the modelname class:
class Modelname < ActiveRecord::Base self.table_name = :tablename self.primary_key = :yonghumingend
Specifically, table and yonghuming respectively specify the corresponding table name and primary key name, so that you do not need to use ID as the primary key of the table.
Problem 2. data cannot be updated when a custom data table is used
When using the above model to update data, the landlord suddenly found that the model could not be updated, and called the rails log to discover, the executed SQL statement is "Update ****** where yonghuming = nil", but I have clearly specified the primary key of the system. After repeated attempts, the author finally determined the problem-using a custom primary key-to solve this problem, the primary key value of the model must be clearly defined, namely:
user = Modelname.find(‘key‘)user.id = ‘key‘......user.update_columns({mima: mima})
Question 3. Deployment of jruby on rails
It can be said that the deployment of jruby on rails is the most painful link in this development process. Repeated attempts, repeated tests, and countless crashes. The biggest problem in deployment is the storage of various files.
1. This deployment uses the Warbler tool for deployment.
2. Before deployment, we recommend that you store all jar files in the Lib folder.
3. When the jar package is called in the ruby file, use require '*****. jar' directly'
4. In addition, read the configuration file (mainly the configuration file to be read by the jar package). We recommend that you cancel the following comments in the warble configuration file:
Config. java_classes = filelist ["relative path of the configuration file"]
After completing the above work, we can basically avoid the deployment problem of jruby on rails (maybe ......)
A painful life-notes on development and deployment of jruby on rails