Skip to content

Instantly share code, notes, and snippets.

@almapase
Last active August 15, 2016 06:36
Show Gist options
  • Save almapase/05e51ade1be50eb74f6707a022017762 to your computer and use it in GitHub Desktop.
Save almapase/05e51ade1be50eb74f6707a022017762 to your computer and use it in GitHub Desktop.
My tips while developing PCM Software

Actualizar Ruby y Rails con rvm

instalar ruby 2.3.1

~ rvm install 2.3.1

definir la version 2.3.1 por defecto en rvm

~ rvm use --default 2.3.1

Crear un Gemset para PCM

~ rvm use 2.3.1@Gemset_pcm --create

Ver todos los Gemset

~ rvm gemset list_all

Instalar rails 4.2.7 en ese Gemset

~ gem install rails 4.2.7

  • Comando erroneo al no colocar v 4.2.7, provoco que se intalara Rails 5
  • Lo corregimos con ~ gem install rails v 4.2.7, con esto tenemos las dos gemas intaladas.

Ahora para crear un proyecto con una version en particular de rails

~ rails _4.2.7_ new [nombre_del_proyecto]

Usando secrets.yml

use-rails-4-secrets-yml-for-database-config

  • Update .gitignore to include config/secrets.yml
  • Add the a database section to config/secrets.yml Note the explicit use of symbols.
development:
  database:
    :host: localhost
    :name: my_project_development
    :username: root
    :password: password
  • add database section to all envs...
  • Update config/database.yml to look like something like this.
default: &default
  host: <%= Rails.application.secrets[:database][:host] %>
  adapter: postgresql
  encoding: UTF8
  database: <%= Rails.application.secrets[:database][:name] %>
  pool: 10
  reaping_frequency: 30
  username: <%= Rails.application.secrets[:database][:username] %>
  password: <%= Rails.application.secrets[:database][:password] %>

development: *default
test: *default
production: *default

Original application.js

//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .

Original application.css

*
*= require_tree .
*= require_self

How To: Display a custom sign_in form anywhere in your app

Example with form_for and posting to user_session_path:

<%= form_for(:user, :url => session_path(:user)) do |f| %>
  <%= f.text_field :email %>
  <%= f.password_field :password %>
  <%= f.check_box :remember_me %>
  <%= f.label :remember_me %>
  <%= f.submit 'Sign in' %>
  <%= link_to "Forgot your password?", new_password_path(:user) %>
<% end %>

Note: "user" in this context is the resource you specified when setting up Devise.

Warning for client_side_validations Whilst the above method works, it should be noted that using the name of a resource as the first parameter for form_for is now deprecated in Rails. I ran into this problem whilst trying to integrate client_side_validations with devise and it choked on this form. I don't know if this is the best work around but in the end, I got it working by leaving the devise form_for as it looks normally: @form_for(resource, :as => resource_name ... )@

Now the trick is defining those helper methods in other controllers. Assuming your devise model is called "user", place the following methods either in the helper class of the controller you are using to display the form or in your application helper:

  helper_method :resource_name, :resource, :devise_mapping

  def resource_name
    :user
  end
 
  def resource
    @resource ||= User.new
  end
 
  def devise_mapping
    @devise_mapping ||= Devise.mappings[:user]
  end

Another advantage of this method is that you don't need to alter the default devise forms. Just move them into a partial and render them wherever you want.

Source: "http://pupeno.com/blog/show-a-devise-log-in-form-in-another-page/":

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment