Installing ImageMagick on Windows to Install RMagick
Suresh Raj Bhattarai
1:43 PM
Before installing RMagick on your machine, it is necessary to install ImageMagick on your machine first. To install ImageMagick, follow the link below:
https://github.com/rmagick/rmagick/wiki/Installing-on-Windows
To install RMagick, include the following line on your gem file
gem 'rmagick'
and run following command line.
bundle install
https://github.com/rmagick/rmagick/wiki/Installing-on-Windows
To install RMagick, include the following line on your gem file
gem 'rmagick'
and run following command line.
bundle install
Easiest way of adding columns to migration table
Suresh Raj Bhattarai
12:21 PM
Easiest way to add columns to the migration table is to run migration from command mode. For example:
If two columns let's say: image (string) and email (string) are to be added to staffs table, then run the statements like this in command mode.
If two columns let's say: image (string) and email (string) are to be added to staffs table, then run the statements like this in command mode.
rails g migration add_columns_to_staffs image:string email:string
Differences between nil, empty and blank
Suresh Raj Bhattarai
4:53 AM
nil? - checks to see if variable is referencing an object or not
empty? - may be used to check on various object types like empty string "" or empty array []
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
Drupal : Adding/Creating new user role
Suresh Raj Bhattarai
11:25 AM
- Go to "Home » Administration » People » Permissions"
- Select the roles shown at the top right
- Add a new role using the input textbox at the bottom
Your role will be created.
WAMP: Changing the default port no of Apache
Suresh Raj Bhattarai
10:01 AM
After running the WAMP server, if the page displays the error like following, then it is the time to change the default port of the server (80) which is being occupied by other services like IIS, Torrent clients, Skype etc.
Not Found
HTTP Error 404. The requested resource is not found.
So change the port on which Wamp listens:
- Click on Wamp server -> Apache -> httpd.conf
- Change
Listen 80to something else, eg:Listen 81 - I would also change
ServerName localhost:80toServerName localhost:81
If you've done this, and saved httpd.conf, you have to restart the Wamp server. Then use
localhost:81 as your root url.
So the urls will then look like
localhost:81/phpmyadmin
localhost:81/your_directory
How to prevent multiple inserts when submitting a form in PHP?
Suresh Raj Bhattarai
1:26 AM
Include a unique token on each POST. In this case, you would also set a session variable to the token you want to include and then render the token in the form. Once the form is submitted, you re-generate the token. When the submitted token does not match the token in your session, the form has been re-submitted and should be declared invalid.
// form.php
php
// obviously this can be anything you want, as long as it is unique
$_SESSION['token'] = md5(session_id() . time());
?>
<form action="foo.php" method="post">
<input type="hidden" name="token" value="" />
<input type="text" name="bar" />
<input type="submit" value="Save" />
</form>
// foo.php
if (isset($_SESSION['token']))
{
if (isset($_POST['token']))
{
if ($_POST['token'] != $_SESSION['token'])
{
// double submit
}
}
}
To Disable "Signup for new account" @ MantisBT
Suresh Raj Bhattarai
4:05 AM
In config_inc.php file, set the following"
"$g_allow_signup = OFF;"
Subscribe to:
Comments
(
Atom
)

No comments :
Post a Comment