Thursday, 4 October 2018

Password update

Routes.rb :

resources :users do
    collection do
      patch 'update_password'
    end
  end
  get 'change_password' => "users#change_password"


users_controller.rb :

def change_password
    @user = current_user
  end
  def update_password
    @user = current_user
    unless @user.valid_password?(params[:user][:current_password])
      @user.errors.add(:base, "Current Password is incorrect.")
      return render "change_password"
    end
    if @user.update(user_params)
      # Sign in the user by passing validation in case their password changed
      bypass_sign_in(@user)
      redirect_to root_path
      #redirect_to destroy_user_session_path
    else
      render "change_password"
    end
  end

Monday, 10 September 2018

Bitbucket runing time out error and bitbucket is not open

Open terminal:

run---  nautilus /etc/hosts

open file Sublime text

127.0.0.1 localhost
127.0.1.1 rinku-HP-Notebook

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes

ff02::2 ip6-allrouters
104.192.143.2 bitbucket.org   ----- this line remove


then save file
Password: system password


https://askubuntu.com/questions/17062/how-to-open-a-directory-folder-and-a-url-through-terminal

Wednesday, 5 September 2018

uploading big image for inginx

Following link:

https://stackoverflow.com/questions/26717013/how-to-edit-nginx-conf-to-increase-file-size-upload

/etc/nginx/nginx.conf

Now that you are editing the file you need to add the line into the server block, like so;
server {
    client_max_body_size 500M;

    //other lines...
}
If you are hosting multiple sites add it to the http context like so;
http {
    client_max_body_size 500M;

    //other lines...
}
And also update the upload_max_filesize in your php.ini file so that you can upload files of the same size.

Thursday, 28 June 2018

Fix hp wifi problem

1. First:

sudo modprobe -rv rtl8723be

sudo modprobe -v rtl8723be ant_sel=2
2. Second:
sudo modprobe -rv rtl8723be
sudo modprobe -v rtl8723be ant_sel=1

Wednesday, 6 June 2018

Devise form anywhere rails

Application controller:-

helper_method :resource_name, :resource, :devise_mapping, :resource_class

  def resource_name
    :user
  end

  def resource
    @resource ||= User.new
  end

  def resource_class
    User
  end

  def devise_mapping
    @devise_mapping ||= Devise.mappings[:user]
  end

Tuesday, 15 May 2018

Redirect back to current page after sign in, sign out

Redirect back to current page after sign in, sign out


Applications_controller.rb


after_filter :store_location


    def store_location
      # store last url - this is needed for post-login redirect to whatever the user last visited.
      return unless request.get?
      if (request.path != "/users/sign_in" &&
          request.path != "/users/sign_up" &&
          request.path != "/users/password/new" &&
          request.path != "/users/password/edit" &&
          request.path != "/users/confirmation" &&
          request.path != "/users/sign_out" &&
          !request.xhr?) # don't store ajax calls
        session[:previous_url] = request.fullpath
      end
    end

    def after_sign_in_path_for(resource)
      session[:previous_url] || root_path 
    end
  def after_sign_out_path_for(resource)
     request.referrer|| root_path
   end

Thursday, 10 May 2018

PREVIEW AN IMAGE AND VIDEO BEFORE IT IS UPLOADED

Please take a look at the sample JS code below:

<script type="text/javascript">
  function readURL(input) {
    if (input.files && input.files[0]) {
    var reader = new FileReader();

    reader.onload = function (e) {
    $('#blah').attr('src', e.target.result);
    }

    reader.readAsDataURL(input.files[0]);
    }
  }

  $("#imgInp").change(function(){
    readURL(this);
  });
</script>


and the associated HTML:


<div class="field">
    <%= form.label :image %>
    <%= form.file_field :image,  id: "imgInp" %>
    <img id="blah" src="#" alt="your image" style="height: 150px; width: 200px;" />
  </div>


================================================================

Preview Video Before Saving



We can follow :-