Adding a record in Rails through javascript

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You would like to trigger a record insertion after a specific action has happened through javascript (ie drag – drop an item into a container), in a rails application.

 

Solution

You would need to get the object attributes from the html page somehow (ie user_id and user_name), and then have a function in your application js that calls the post function.

So if you have a drag and drop container for example then the code in the application.js should be like the following:

 

Connect to a remote MySQL server with MySQLBrowser using SSH

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You would like to connect to a remote MySQL server using the Mysql-query-browser GUI tool, and you only have localhost access to the remote server, but also have ssh access to the remote server.

 

Solution

You can use the following command to start a port forwarding to your localhost and then use that to connect to the remote database server:

You could then use the following to the Mysql-query-broser connection:

 

Replacing mock objects with factory girl in controller rspecs

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You would like to use factory_girl instead of the mock models described in the RSpec book (Behaviour Driven Rails – Rails Controllers – Controller specs).

 

Solution

Make sure that you use let! instead of let and have the following:

 

command line multiple pnm conversion to single pdf file

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You have multiple scanned images as pnm files, and you would like to convert them to a single pdf file.

 

Solution

If you have imagemagick installed you should be able to use the convert as follows to combine the images to one pdf file:

Parent task translation missing: en, activerecord, errors, models, issue, attributes, parent_issue_id, not_a_valid_parent

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem
You get the following error in redmine when trying to update a task that has a parent task.

Solution
It seems that for some reason when you add more than one subtask, the lft and rgt id numbers are not created correctly so you cannot update the subtasks.
If the numbers are overlapping (rgt for first subtask 2 and lft for second subtask 2), then there is a problem.
So in order to be able to solve that you will need to change the lft, rgt ids to have subsequent numbers as:
first subtask: lft -> 1 , rgt -> 2
second subtask: lft -> 3, rgt -> 4

ERD diagrams in Ruby on Rails

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You would like to have an ERD diagram of your database in your Ruby on Rails project.

Solution

You can install the Rails ERD from here, and install it by following the instructions.
For Ubuntu/debian systems should be:

and then adding the gem to your Gemfile in the development section as:

You can then run bundle install to install the gem and rake erb to create the diagram pdf.

Pausing between steps in cucumber

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

Problem

You want to be able to go through a scenario step by step when you are testing with a browser as sometimes can be very fast.

 

Solution

By following the suggestion here you would only need to add the following to your features/support/hooks.rb file

and then you should be able to use it in your scenario by adding the @pause tag.
Then you would have to press continue in your terminal to go step by step