• PHP
  • Ruby on Rails
  • MySQL
  • Linux
    • SELINUX
    • Fedora
    • debian
  • Apache
  • nginx
  • AJAX
Albertech.net

Easiest way to filter out text in a MySQL field

August 29, 2017 6:53 pm / Albertech.net

Example:  Removing the “.0” from an Excel import into MySQL

  • MYTABLE – The MySQL Table Name
  • FIELDNAME – The field you wish to edit the data
  • Make sure you have a primary key defined, I usually set mine as “id” for the table. If you are using a different name for the primary key ID, replace the “id” with the different name.

UPDATE MYTABLE AS T1, MYTABLE as T2 SET T1.FIELDNAME = replace(T2.FIELDNAME,’.0′,”) WHERE T2.id = T1.id;

Before running this query, make sure you make a backup in case it doesn’t work correctly.

Share this:

  • Facebook
  • Google
  • Twitter
  • Print
  • Email
Posted in: MySQL / Tagged: MySQL

Rails – jQuery generating extra HTML headers after AJAX call

May 24, 2017 12:54 pm / Albertech.net

If you get the following extra HTML headers after using the jQuery AJAX method on a page and immediately clicking on another link:

0
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
Content-Type: text/html; charset=utf-8
X-UA-Compatible: IE=Edge
Transfer-Encoding: chunked

Tracing back to my webapp, it looks like the error was due to jQuery expecting a callback from my Rails AJAX method. It times out automatically after a few seconds, but if you click on another link immediately after it will generate additional HTML headers. To fix this, I added a new response to the script as a JSON.

In my Rails app, I added the following line to the corresponding method in the controller:
render json: nil, status: :ok

Ruby 3+

I didn’t have to make any additional changes on the jQuery script. The following worked for me without any issue:
$.ajax({
url : "/myapp/myajaxscript",
type: "POST",
data : formData,
success: function(data,status)
{
console.log(status);
}
});

Share this:

  • Facebook
  • Google
  • Twitter
  • Print
  • Email
Posted in: AJAX, jQuery, Ruby on Rails

Permit nested attributes in Rails 4

November 2, 2015 6:33 pm / Albertech.net

In order to use nested attributes in Rails 4, one must use the params.require method inside controller with the _attributes keyword and the list of fields inside the nested model. This is a good option if the keys of the nested models are known.

Here’s a simplified version of what it would look like. The question_params method inside the controller will have the nested model answer setup with answer_attributes: [:id, :response].

/controllers/question_controller.rb

class QuestionController > ApplicationController
  def new
    if params[:question].present?
      @question = Question.new(question_params)
    else
      @question = Question.new
    end
  end

private
  def question_params
    params.require(:question).permit(:id, :name, answer_attributes: [:id, :response])
  end
end

 

/models/question.rb

class Question > ActiveRecord::Base
has_many :answers
  accepts_nested_attributes_for :answers
end

/models/answer.rb

class Answer > ActiveRecord::Base
  belongs_to :question
end

Note: If you want to whitelist all nested parameters, you can use the code at: https://github.com/rails/rails/issues/9454#issuecomment-14167664. This would eliminate the need to list each of the nested models individually.

Share this:

  • Facebook
  • Google
  • Twitter
  • Print
  • Email
Posted in: Ruby on Rails / Tagged: nested attributes, strong parameters

Custom OmniAuth Callback URL

August 18, 2015 6:42 pm / Albertech.net

If you have Ruby on Rails App and want to use a custom OmniAuth Callback URL (Something other than /auth), there is a configuration value that you can set.

/config/initializers/omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, {
 :callback_path => "/myauth/shibboleth/callback"
}
end

Replace “myauth” with the path that you prefer to use. This will allow for a different callback URL when users aren’t logged in. Tested with Rails 4.2 and Ruby 2.2.

Share this:

  • Facebook
  • Google
  • Twitter
  • Print
  • Email
Posted in: Ruby on Rails / Tagged: omniauth

Fix: Windows 7 clients unable to connect to Samba 3

January 14, 2015 2:39 pm / Albertech.net

If you are using Samba 3 and have issues with Windows 7 clients connecting to the share, the easiest fix is to upgrade to Samba 4.

A recent Windows security update released in Fall 2014 causes an error in Samba “Server exit (failed to receive smb request)” and on the Windows end “The specified server cannot perform the requested operation”. This appears to be compatibility issue with Samba 3.X and Windows 7. Rolling back the Windows update makes the problem disappear. So, the best option is to upgrade to Samba 4.

Before you upgrade, make sure you back up the existing smb.conf file. Upgrading Samba will overwrite the existing smb.conf file. In RedHat, use yum to remove the samba-common and samba libraries and install the samba4 package.

 

 

Share this:

  • Facebook
  • Google
  • Twitter
  • Print
  • Email
Posted in: Linux / Tagged: samba, windows 7

Post Navigation

← Older Posts
 

Categories

  • AJAX
  • Android
  • Apache
  • Canon Cameras
  • Cloud
  • CMS
  • Computer Mods
  • Conferences
  • Deals
  • debian
  • Fedora
  • Flash
  • Frameworks
  • git
  • Hardware
  • HTML
  • IDE
  • iPhone
  • iPhone App Review
  • jQuery
  • Linux
  • Mac OS X
  • MySQL
  • nginx
  • PHP
  • portfolio
  • Puppet
  • Ruby on Rails
  • Script Reviews
  • SELINUX
  • Software
  • Software Review
  • SQL Server
  • statistics
  • Tech
  • Tomcat
  • Uncategorized
  • VMWARE
  • VPS
  • Windows
  • wordpress
  • Zend Framework

Blogroll

  • DragonAl Flickr
  • Dropbox – Free 2GB Account
  • James' Blog
  • Javascript Compressor
  • PHP Builder Community
  • PHP-Princess.net
  • Rubular – Regular Expression Validator
  • The Scale-Out Blog
  • Tiny MCE

Tags

activation AJAX android antec Apache AWS awstats canon coda codeigniter debian enclosure external free G1 install vmware tools Internet Explorer iphone 5 jquery Linux mx-1 MySQL office 2007 OSX photoshop PHP plugin plugins portfolio redesigned website review rewrite script security SELinux ssh tinymce tutorial upgrade VMWARE vmware server wordpress wordpress mu XSS zend framework
© Copyright 2013 Albertech.net
Infinity Theme by DesignCoral / WordPress
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.