Web progamming and database development

Diary of problems and solutions related to web programming, database development and related technologies and platforms.

Installing ImageMagick on Windows to Install RMagick

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

No comments :

Post a Comment

Easiest way of adding columns to migration table

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.

rails g migration add_columns_to_staffs image:string email:string

No comments :

Post a Comment

Differences between nil, empty and blank

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 []
blank? - checks for nil? or empty?.

No comments :

Post a Comment

Associating multiple foreign keys to a migration table or a primary key

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

No comments :

Post a Comment

Duplicating project on Ruby on rails

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.

End

No comments :

Post a Comment

Drupal : Adding/Creating new user role

  1. Go to "Home » Administration » People » Permissions"
  2. Select the roles shown at the top right
  3. Add a new role using the input textbox at the bottom
Your role will be created.

No comments :

Post a Comment

WAMP: Changing the default port no of Apache

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 80 to something else, eg: Listen 81
  • I would also change ServerName localhost:80 to ServerName 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

No comments :

Post a Comment

How to prevent multiple inserts when submitting a form in PHP?

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
        }
    }
}

No comments :

Post a Comment

To Disable "Signup for new account" @ MantisBT

In config_inc.php file, set the following"

"$g_allow_signup = OFF;"

No comments :

Post a Comment