In one of my Rails views, I’m using a remote form that submits via AJAX. On the ajax:success callback, I wanted the page to be redirected, while allowing the user to go back i.e. maintain page history.
Here are two ideas that didn’t work:
- A ‘redirect_to’ call in the controller that handles the POST request. The redirect_to call is ignored.
I also tried this out with an HTML link. However for some reason, the jQuery click() function does not trigger clicks on HTML links.
UPDATE: Turns out the back button works only the first time. If I do this twice, and then hit ‘Back’, I go back to the first page. [TODO: Elaborate.]
To be frank, I’ve never been very comfortable with Rails form helpers. Today, I had to display forms for multiple objects of the same class in the same view.
It took me longer than usual to find a solution for this. You have to use the namespace option in the form_for method. Read more here – http://apidock.com/rails/v3.2.8/ActionView/Helpers/FormHelper/form_for
Example follows in the gist below:
Today, I ran into a problem where I committed hastily and realized that it combined two aspects of my code which I wanted to keep in distinct commits. After a bit of Googling the following workflow fixed the issue.
Most courses at Stanford require use of myth/corn clusters for the programming assignments.
I’ve tried using tmux on those clusters, but the experience hasn’t been very good. For some reason, when I detach the tmux session, log out, log in and attach the session again, it somehow loses permissions to write to my files.
Myth and Corn don’t work with ssh keys either, which means I have to resort to opening multiple terminal window/tabs and enter my password everytime.
Adding the following to my /etc/ssh_config file reduces some of the pain, by auto-logging me in, if I have one open session.
Credit goes to Kyle, for this handy tip.
I’ve come across a few ways to improve my irb/rails console experience. You could either try to enhance it using hirb or wirble, or you could swap it out for the powerful pry.
Here’s a basic comparative screenshot, to make you want to give it a shot. An example of the awesomeness that lies ahead is the ‘nesting’ feature, which allows you to dig into your classes and their instances the way you would dig into a folder tree. As always, the railscast on pry is pretty neat.
lol-worth: ‘wtf?’ prints out information about the last observed exception
I use the rails console a lot while fiddling around with pieces of my Rails code base. Every time I made changes, I’d exit it and restart it again. Until today. In a fortuitous sequence of events, I chanced upon the reload! command, which pulls in the latest changes to your code without needing to exit the console!
I have been exploring easy ways of booting a custom tmux session. I gave the tmuxinator a shot today and really liked it.
I wish there was an easy way of shutting down my tmux session though without manually having to CTRL-D every pane.
This is the yml I’m using for my Rails projects:
This is what the tmux man page says about layouts. You can read more about layouts here.
M-1 to M-5 Arrange panes in one of the five preset layouts: even-
horizontal, even-vertical, main-horizontal, main-
vertical, or tiled.