Thoughts, information and reflections about technology

Ruby-on-rails

Ruby on Rails Tips including general tips and specific coding methods.

 

Ruby on Rails – Shading cells depending on the value of the cell

There will be times when you might want to change the shading of a cell in a table depending on the value of that cell.

I wanted to change the background color of a cell depending on if the contents of the expires field was past or not.  This could be useful for dashboard type apps or pages. i.e. red/yellow/green

index.html Continue reading

Ruby on Rails – Show a field only if the controller is ‘new’

There can be times when you want to show a field, or do some other action, only for a  certain controller action such as ‘new’.

In this example, we have a form and we want to the currently logged in user (@current_user_name in this case) if this is a new complaint. However if we are editing we want to show the name of the user in the user table (@user.name) Continue reading

Ruby on Rails – Setting the accepted parameters to allow hashes.

There are times when you need to store a hash/array in a field in a rails table. 

By declaring a hash and putting it at the end of the params permit section, then the data from things such as a multi select will be stored as a hash. Adding => [] declares the field as a hash field. 


def 
search_params
params.require(:search).permit(:document_title,
:summary,
:owner,
:category,
:file_name,
:doc_to_email,
:category => [],
:owner => [])

Continue reading

Rails – Adding the user’s active directory email to the User model when using Adauth

I use adauth to authenticate users in my Rails apps using their Active Directory information. A model and table called User(s) gets created.

However, the standard setup for Adauth does not grab the user’s email address as it appears in Active Directory. You can grab and store the email using the following method. Continue reading

Rails – What to do check your date searches are not showing the results you expect.

Some dates will need to be stored in a date time format.  This does not pose a problem when you are searching for dates equal to or greater than a specific date. You also avoid problems if you are storing dates in a date format.

However, if you search for a date less than or equal to a specific date using a datetime column, your results do not include that date. In other words, if you set up a search to show you everything where the date in question was less than or equal to 3/25/2016 you would not get any records where the date was 3/25/2016.

Continue reading

Rails – Changing the attributes of the flash notice

Some of the apps I do make a lot of use of the Rails flash notices. The default text attributes don’t make the notice stick out enough. I wanted to use a yellow background to highlight any notices. 

Using the Inspect tool in chrome, I found that the controlling CSS was in assets/scaffolds.scss. In my case it happened to be around line 39

Look for #notice.  The only attibute was color: green;. I changed that to add a yellow background color as follows Continue reading

Contact me
Archives
Categories