• rake db:migrate for an existing model

Firstly I created new rails app, after that created several models, or you make some changes on your model manually(wrong way), while you are running rake db:migrate getting error for an existing model in your app. For fix that issue you can write,

1
rake db:schema:load

or

1
2
3
4
5
rake db:drop
rake db:create
rake db:migrate
rake db:schema:dump
rake db:text:prepare
  • background-image use in haml

1
%li{style: "background-image: url(#{image_path "image.png"})"}
  • In rails, if you give / to path, this means that look to public directory.
  • bundle exec rake db:drop db:create db:migrate

  • Rename table more easier with Migration!

1
2
3
class RenameOldTableToNewTable < ActiveRecord::Migration
    rename_table :old_table_name, :new_table_name
end
  • Radio button on with simple_form

1
2
3
4
5
6
7
8
= simple_form_for @new do |new|
    =  new.error_notification
    .form-inputs
        = f.input :title
        - ['Url', 'file'].each do |content|
            %label
                = new.radio_button(:file, content)
            = content.humanize
  • Getting data from admin panel to home

Getting all data or some data which is added in admin panel to show in home .

1
2
3
4
5
6
class WelcomeController < ApplicationController
  def index
    @news = New.all.order(id: :desc) // you can give limit like
    @news = New.all.order(id: :desc).limit(10) // taking limited data
  end
end
1
2
3
- @news.each do |new|
    %p
        = link_to '{new.title}', '{new.url}'

For contact form in your app,

1
2
3
4
5
6
7
8
9
--config/settings.yml, config/settings/development.yml, config/settings/production.yml, config/settings/staging.yml --
smtp:
  mandrill:
    address: 'smtp.mandrillapp.com'
    port: 123
    enable_starttls_auto: true
    user_name: 'your_mail',
    password: 'your_api_password'
    authentication: 'plain'
1
2
3
4
5
6
7
8
--config/environments/development.rb and config/environments/production.rb --
  config.action_mailer.smtp_settings = {
      address: 'smtp.mandrillapp.com',
      port: 123,
      enable_starttls_auto: true,
      user_name: 'your_mail',
      password: 'your_api_password',
  }
  • Deploy to server with capistrano shortly

for server-base.sh

1
2
3
4
ssh username@ip_adress
wget url/server-base.sh
ls-al
chmod +x server-base.sh

if give you permission denied please use sudo su

1
2
sudo su
./server-base.sh

Same way for deploy-user.sh and after that open new tab in term

1
2
3
4
5
ssh deploy@ip_adress
wget url/deploy-user-env.sh
ls-al
chmod +x deploy-user-env.sh
./deploy-user-env.sh

For deploy-user-env.sh if give you language exception open /etc/environment

1
2
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8

After that use recipes_matic gem for install capistrano and all derivatives . Then make all customizations.

That ’s all, I hope solve your issues.

Comments