Skip to main content

Posts

Paperclip uploading files (or)images to amazon s3 for Ruby on rails?

Paperclip uploading files (or)images to amazon s3 for Ruby on rails ? 1)Add a gem 'gem 'aws-sdk' 2)bundle install 3)app/models/profile.rb-----Model add this code has_attached_file :image,                    :storage => :s3,                    :bucket => "yyyyyy",                    :s3_permissions => "public-read",                    :path => "profiles/:id/:basename.:extension",                    :s3_credentials => {                 ...

rake db:rollback in rails

rake db:rollback in rails ? General-> rake db:migrate ->This will migrate your database by running migrations that are not run yet Running ->specific Migration     ->rake db:migrate VERSION=20130717110623 ->    This runs specific migration file from your db/migrate directory having version 20130717110623 Running up from migration->     rake db:migrate:up VERSION=20130717110623 ->    This runs up part from your migration Running down from migration ->    rake db:migrate:down VERSION=20130717110623     ->This runs down part from your migration Re-Running Specific Migration ->    rake db:migrate:redo VERSION=20130717110623 ->    This will first run down part and then up part of the migration having version 20130717110623 Re-Running all migrations     ->rake db:migrate:redo ->    This will re-run all t...

Can you get DB username, pw, database name in Rails?

Can you get DB username, pw, database name in Rails? Rails.configuration.database_configuration[Rails.env] => {"encoding"=>"unicode", "username"=>"postgres", "adapter"=>"postgresql", "port"=>5432, "host"=>"localhost", "password"=>"postgres", "database"=>"mydb", "pool"=>5} (or) config   = Rails.configuration.database_configuration host     = config[Rails.env]["host"] database = config[Rails.env]["database"] username = config[Rails.env]["username"] password = config[Rails.env]["password"] (or) con = Mysql.real_connect("host", "user", "pw", "current_db") (or) Rails.configuration.database_configuration["development"]["database"]   

Create migration files in rails from existing mysql table

Create migration files in rails from existing mysql table? Start by referencing your existing MySQL database in database.yml run rake db:schema:dump to generate the schema.rb file Paste the create_table methods from your schema.rb into a new migration, and Voila! ##generate schema.rb ruby script/generate migration Tabledata migration file inside add the schema.rb remove this line 1)ActiveRecord::Schema.define(:version => 0) do end 2)rake db:migrate    

Get user accessing ip address in rails?

Get user accessing ip address rails? request.ip ->returns the ip, whether is is a local proxy ip (localhost address) or not. *request.remote_ip -> is smarter and gets the ip address of the client outside of local proxies. 3)If you are using apache in front of a mongrel, then remote_ip will return the source address of the request, which in this case will be local host because the Apache web server is making the request, so instead put this in your controller: @remote_ip = request.env["HTTP_X_FORWARDED_FOR"]

Mysql Queries

Mysql Queries ? 1)createing table in mysql create table users(id int not null primary key,name char(25),address varchar(100),dob date); (or) CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), PRIMARY KEY (P_Id) ) 2)inserting data to tables; insert into  users(id,name,address,dob) values(1,"sanjeevreddy","kachiguda",STR_TO_DATE('1-01-2012', '%d-%m-%Y')) 3)Add coloumn to mysql table alter table users add column last_name varchar(255) not null ,add column  email varchar(240); 4)deleting table drop table profiless; drop table table_name; 5)updating table data  update users set name ="reddy" where id = 1; 6)total databases show databases; 7)show table attributes desc table_name; desc users; ===================================== Database A database consists of one or more tables. A table is identified by its name. A ta...