Associating multiple foreign keys to a migration table or a primary key
Suresh Raj Bhattarai
1:46 PM
Step: Generating Scaffold
We are referencing the table codeorganization for creating multiple foreign keys for a same primary key ie codeorganisation_id
rails g scaffold dataform report_date:date organisation:references organisation_reported:references
Step: Point the referenced id to the model and make changes in Model
Change
class Dataform < ActiveRecord::Base
belongs_to :organisation
belongs_to :organisation_reported
end
To
class Dataform < ActiveRecord::Base
belongs_to :organisation, :class_name => "Codeorganisation"
belongs_to :organisation_reported, :class_name => "Codeorganisation"
end
Step: By default the those fields in the Controllers do not change and the fields are not in permitted mode when we try to add or edit the dataform records Change
def dataform_params
#params.require(:dataform).permit(:codeorganisation_id, :codeorganisation_id)
end
To
def dataform_params
#params.require(:dataform).permit(:organisation_id, :organisation_reported_id)
end
For this, also refer the following related articles
Duplicating project on Ruby on rails
Suresh Raj Bhattarai
7:00 AM
Create a folder lets say "railsnewprj_temp" though the project folder name is going to be "railsnewprj"
Lets say the old rails project's name is ":railsproject". In config/database.yml file, replace the following
database: railsproject_development
database: railsproject_test
database: railsproject_production
username: railsproject
password: <%= ENV['RAILSPROJECT_DATABASE_PASSWORD'] %>
by
database: railsnewprj_development
database: railsnewprj_test
database: railsnewprj_production
username: railsnewprj
password: <%= ENV['RAILSNEWPRJ_DATABASE_PASSWORD'] %>
Create a new rails project
C:\row\dev>rails new railsnewprj -d mysql
Go to railsnewprj
C:\row\dev>cd railsnewprj
Create database
C:\row\dev\railsnewprj>rake db:create
This will create database in mysql
Copy the files and folders inside railsnewprj_temp to railsnewprj
Migrate ie run the migration files (that has been copied to the railsnewprj folder)
C:\row\dev\railsnewprj>rake db:migrate
Copy the record related to administrators' username and password so that s/he can login to the system.
Installing any of the dependencies. Let's say ImageMagick installer (See this for more details) for managing Image uploads and so on.
Installing any of the dependencies. Let's say ImageMagick installer (See this for more details) for managing Image uploads and so on.
End
Subscribe to:
Comments
(
Atom
)
No comments :
Post a Comment