I want to save the content of a page with the system command curl but it's not working.
I think it's a problem with localhost but I don't know how to solve this.
def save_page
`/usr/bin/curl -O http://127.0.0.1:3000/category_plist`
end
Server output:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:04:54 --:--:-- 0
If you change your function to the following it should work ...
def save_page
system("/usr/bin/curl -O http://127.0.0.1:3000/category_plist")
end
To test commands like this, exit your local webserver and run "rails console", from there you can enter a command such as this and get an immediate response ...
$ rails console
Loading development environment (Rails 3.1.0.rc4)
1.9.2-p290 :001 > puts system("ls -l")
total 56
-rw-r--r--# 1 creativetechnologist staff 212 3 Feb 2011 Capfile
-rw-r--r--# 1 creativetechnologist staff 924 6 Feb 2012 Gemfile
-rw-r--r--# 1 creativetechnologist staff 3072 6 Feb 2012 Gemfile.lock
-rw-r--r--# 1 creativetechnologist staff 3943 16 Oct 23:16 MOR_git.tmproj
-rw-r--r--# 1 creativetechnologist staff 18 12 Jul 19:06 README
-rw-r--r--# 1 creativetechnologist staff 267 30 Aug 2011 Rakefile
drwxr-xr-x 7 creativetechnologist staff 238 30 Aug 2011 app
drwxr-xr-x 11 creativetechnologist staff 374 13 Sep 2011 config
-rw-r--r--# 1 creativetechnologist staff 157 30 Aug 2011 config.ru
drwxr-xr-x 6 creativetechnologist staff 204 3 Feb 2011 db
drwxr-xr-x 3 creativetechnologist staff 102 3 Feb 2011 doc
drwxr-xr-x 4 creativetechnologist staff 136 3 Feb 2011 key
drwxr-xr-x 6 creativetechnologist staff 204 7 Sep 2011 lib
drwxr-xr-x 6 creativetechnologist staff 204 11 Mar 2012 log
drwxr-xr-x 3 creativetechnologist staff 102 30 Aug 2011 logs
drwxr-xr-x 13 creativetechnologist staff 442 6 Feb 2012 public
drwxr-xr-x 3 creativetechnologist staff 102 3 Feb 2011 script
drwxr-xr-x 8 creativetechnologist staff 272 3 Feb 2011 test
drwxr-xr-x 6 creativetechnologist staff 204 3 Feb 2011 tmp
drwxr-xr-x 3 creativetechnologist staff 102 3 Feb 2011 vendor
true
=> nil
1.9.2-p290 :002 >
Hope that helps.
Try this:
def save_page
`/usr/bin/curl -s http://127.0.0.1:3000/category_plist` # -s will silent curl's output except the page
end
Related
I am writing Unit Tests in Objective C.
The following is my code:
NSString *testTempDirectory = [NSString stringWithFormat:#"%#%#", NSTemporaryDirectory(), #"DC_Tests"];
NSURL *parentDirURL = [NSURL fileURLWithPath:testTempDirectory];
NSURL *testFolderURL = [NSURL fileURLWithPath:testFolderPath];
Now the path in testFolderURL is returned as
/var/folders/31/2dpztnmx4fzfxb87qtn5_n0wc49pvz/T/DC_Tests/testFolder/
But the original path is
/private/var/folders/31/2dpztnmx4fzfxb87qtn5_n0wc49pvz/T/DC_Tests/testFolder/
The original path is my expected path and since it is different, my assertion is failing.
Any idea as to how do I get the complete path.
Note: I tried absolute string, doesn't help.
Note that in Mac OS, the var folder is actually a linked folder to /private/var
$ ls -l /
total 45
drwxrwxr-x+ 61 root admin 2074 Jun 11 08:58 Applications
drwxr-xr-x+ 63 root wheel 2142 Jul 6 2016 Library
drwxr-xr-x# 2 root wheel 68 Aug 24 2015 Network
drwxr-xr-x# 4 root wheel 136 Jun 9 18:56 System
drwxr-xr-x 6 root admin 204 Apr 22 2016 Users
drwxrwxrwt# 4 root admin 136 Jun 15 09:53 Volumes
drwxr-xr-x# 39 root wheel 1326 Jun 9 18:56 bin
drwxrwxr-t# 2 root admin 68 Aug 24 2015 cores
dr-xr-xr-x 3 root wheel 4312 Jun 9 18:57 dev
lrwxr-xr-x# 1 root wheel 11 Oct 18 2015 etc -> private/etc
dr-xr-xr-x 2 root wheel 1 Jun 9 18:58 home
-rw-r--r--# 1 root wheel 313 Aug 23 2015 installer.failurerequests
dr-xr-xr-x 2 root wheel 1 Jun 9 18:58 net
drwxr-xr-x# 6 root wheel 204 Oct 18 2015 private
drwxr-xr-x# 59 root wheel 2006 Jun 9 18:56 sbin
lrwxr-xr-x# 1 root wheel 11 Oct 18 2015 tmp -> private/tmp
drwxr-xr-x# 13 root wheel 442 Apr 19 2016 usr
lrwxr-xr-x# 1 root wheel 11 Oct 18 2015 var -> private/var
So the simplest way to fix your test is to ignore the /private part from the path. (We had a similar issue with paths that contain the tmp folder on Mac OS as well)
I keep receiving the error SQLite3::ReadOnlyException: attempt to write a readonly database: UPDATE "users" SET "current_sign_in_at" = ?, "sign_in_count" = ?, "updated_at" = ? WHERE "users"."id" = ? when trying to sign into my Rails 4 app which uses the devise gem.
I figured it has something to do with permissions on the dev db so checked out the permissions of the dir first, it has a + tacked onto the end which after some googling still couldn't figure out what it's doing.
-rw-r--r-- 1 a36971 staff 2.1K 24 Jan 20:16 Gemfile
-rw-r--r-- 1 a36971 staff 5.7K 24 Jan 20:16 Gemfile.lock
-rw-r--r-- 1 a36971 staff 47B 7 Jan 22:31 README.md
-rw-r--r--+ 1 root staff 249B 7 Jan 19:57 Rakefile
drwxr-xr-x+ 8 root staff 272B 7 Jan 19:57 app/
drwxr-xr-x+ 7 root staff 238B 7 Jan 19:57 bin/
drwxr-xr-x+ 13 root staff 442B 22 Jan 20:14 config/
-rw-r--r--+ 1 root staff 153B 7 Jan 19:57 config.ru
drwxr-xr-x+ 8 root staff 272B 26 Jan 10:28 db/
drwxr-xr-x+ 4 root staff 136B 7 Jan 19:57 lib/
drwxr-xr-x+ 5 root staff 170B 8 Jan 15:51 log/
drwxr-xr-x+ 7 root staff 238B 7 Jan 19:57 public/
drwxr-xr-x 7 a36971 staff 238B 17 Jan 22:38 spec/
drwxr-xr-x+ 9 root staff 306B 7 Jan 19:57 test/
drwxr-xr-x+ 6 root staff 204B 7 Jan 20:19 tmp/
drwxr-xr-x+ 3 root staff 102B 7 Jan 19:57 vendor/
After cd ing into the db dir you can see there's nothing wrong with the permissions on the db itself:
-rw-r--r-- 1 a36971 staff 44K 26 Jan 09:30 development.sqlite3
drwxr-xr-x 5 a36971 staff 170B 22 Jan 20:14 migrate/
-rw-r--r-- 1 a36971 staff 2.2K 22 Jan 20:14 schema.rb
-rw-r--r-- 1 a36971 staff 1.2K 25 Jan 23:22 seeds.rb
-rw-r--r-- 1 a36971 staff 44K 26 Jan 09:23 test.sqlite3
So my questions are:
a) why is it unable to write to the db when there doesn't appear to be anything wrong with the permissions themselves
b) what does the + mean on mac os?
a) why is it unable to write to the db when there doesn't appear to be anything wrong with the permissions themselves
My best guess is that the db/ directory is owned by the root user, whereas the db/*.sqlite3 files are owned by user a36971. It may be necessary for the db/ directory to also be owned by user a36971.
Try changing the owner from root to a36971 for the db directory:
sudo chown a36971 db
b) what does the + mean on mac os?
+ sign means there are additional permission details not displayed by the default output from ls -l. Try running ls -le to see the details (source: http://tech.enekochan.com/en/2014/05/29/plus-and-at-symbols-listing-file-permissions-in-mac-os-x/).
Got the same error after running rails db:reset
Restarting the local server fixed my problem
I have a rails app called MBAToolbox. When I enter the directory and type "play", I get the following:
This is not a play application!
That's good! Now I type rails c and I am entered into the rails command line. Clearly this is a rails app. But when I type 'heroku create' and push 'git push heroku master', heroku tries to deploy this as a 'play' app?
I saw on their site that Heroku states:
Heroku Play framework support will be applied to applications that
match:
*/conf/application.conf in any directory except for the modules directory
, when determining to use Play.
I don't have that. My directory is as follows:
drwxr-xr-x 21 admin staff 714 Mar 22 00:20 .
drwxr-xr-x 26 admin staff 884 Mar 21 21:39 ..
-rw-r--r--# 1 admin staff 6148 Mar 21 23:37 .DS_Store
-rw-r--r-- 1 admin staff 430 Mar 21 21:39 .gitignore
drwxr-xr-x 12 admin staff 408 Mar 22 00:22 .idea
-rw-r--r-- 1 admin staff 935 Mar 21 22:38 Gemfile
-rw-r--r-- 1 admin staff 3884 Mar 21 22:38 Gemfile.lock
-rw-r--r-- 1 admin staff 9208 Mar 21 21:39 README.rdoc
-rw-r--r-- 1 admin staff 275 Mar 21 21:39 Rakefile
drwxr-xr-x 9 admin staff 306 Mar 21 21:57 app
drwxr-xr-x 10 admin staff 340 Mar 21 21:56 config
-rw-r--r-- 1 admin staff 160 Mar 21 21:39 config.ru
drwxr-xr-x 6 admin staff 204 Mar 22 00:06 db
drwxr-xr-x 3 admin staff 102 Mar 21 21:39 doc
drwxr-xr-x 5 admin staff 170 Mar 21 21:48 lib
drwxr-xr-x 4 admin staff 136 Mar 21 21:39 log
drwxr-xr-x 9 admin staff 306 Mar 21 23:37 public
drwxr-xr-x 3 admin staff 102 Mar 21 21:39 script
drwxr-xr-x 8 admin staff 272 Mar 21 21:39 test
drwxr-xr-x 6 admin staff 204 Mar 21 21:53 tmp
drwxr-xr-x 4 admin staff 136 Mar 21 21:39 vendor
Thoughts?
This article on the Heroku dev site covers both ends of this. It has a pointer to the actual source of the Play buildpack, so you can read the code that figures out which buildpack to use. You can also explicitly pick the Rails buildpack instead.
Ok so I had RVM working before but after I upgraded to Mountain Lion it appears to be gone? So I tried reinstalling it:
Ayman$ curl -L https://get.rvm.io | bash -s stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 185 100 185 0 0 200 0 --:--:-- --:--:-- --:--:-- 755
100 9979 100 9979 0 0 5911 0 0:00:01 0:00:01 --:--:-- 5911
Downloading RVM from wayneeseguin branch stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 125 100 125 0 0 67 0 0:00:01 0:00:01 --:--:-- 102
100 1047k 100 1047k 0 0 159k 0 0:00:06 0:00:06 --:--:-- 245k
Upgrading the RVM installation in /Users/Ayman/.rvm/
RVM PATH line found in /Users/Ayman/.zshrc.
RVM sourcing line found in /Users/Ayman/.zlogin.
Upgrade Notes:
* No new notes to display.
# RVM: Shell scripts enabling management of multiple ruby environments.
# RTFM: https://rvm.io/
# HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)
# Cheatsheet: http://cheat.errtheblog.com/s/rvm/
# Screencast: http://screencasts.org/episodes/how-to-use-rvm
# In case of any issues read output of 'rvm requirements' and/or 'rvm notes'
Upgrade of RVM in /Users/Ayman/.rvm/ is complete.
# Ayman ####,
#
# Thank you for using RVM!
# I sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne
rvm 1.15.5 (stable) by Wayne E. Seguin <wayneeseguin#gmail.com>, Michal Papis <mpapis#gmail.com> [https://rvm.io/]
Should be installed right? Should be ready to go but...
Ayman$ which rvm
Ayman$ rvm requirements
-bash: rvm: command not found
Ayman$ rvm use 1.9.2 --default
-bash: rvm: command not found
Now sure what to do? Looked at my .bash_profile and .bashrc to see what's there:
Ayman$ ls -la
total 136
drwxr-xr-x+ 26 Ayman staff 884 Aug 23 20:44 .
drwxr-xr-x 6 root admin 204 Aug 8 19:27 ..
-rw------- 1 Ayman staff 3 Jun 16 15:21 .CFUserTextEncoding
-rw-r--r--# 1 Ayman staff 21508 Aug 23 08:03 .DS_Store
drwx------ 10 Ayman staff 340 Aug 23 07:57 .Trash
-rw------- 1 Ayman staff 9089 Aug 23 20:47 .bash_history
-rw-r--r-- 1 Ayman staff 106 Aug 22 21:17 .bash_profile
-rw-r--r-- 1 Ayman staff 24 Aug 23 20:47 .bashrc
drwxr-xr-x 3 Ayman staff 102 Aug 21 20:41 .bundler
drwxr-xr-x 3 Ayman staff 102 Jun 24 21:45 .gem
-rw-r--r-- 1 root staff 155 Aug 21 22:52 .gemrc
-rw-r--r-- 1 Ayman staff 61 Aug 21 19:40 .gitconfig
-rw-r--r-- 1 Ayman staff 14 Aug 23 08:14 .irb_history
-rw------- 1 Ayman staff 2415 Aug 23 20:44 .mysql_history
drwxr-xr-x 29 Ayman staff 986 Aug 23 20:58 .rvm
-rw-r--r-- 1 Ayman staff 118 Jun 24 21:25 .zlogin
-rw-r--r-- 1 Ayman staff 59 Jun 24 21:25 .zshrc
drwx------+ 18 Ayman staff 612 Aug 23 08:02 Desktop
drwx------+ 5 Ayman staff 170 Jun 24 23:04 Documents
drwx------+ 19 Ayman staff 646 Aug 22 21:05 Downloads
drwx------# 47 Ayman staff 1598 Aug 9 22:30 Library
drwx------+ 3 Ayman staff 102 Jun 16 15:21 Movies
drwx------+ 5 Ayman staff 170 Jun 24 23:05 Music
drwx------+ 57 Ayman staff 1938 Aug 19 22:40 Pictures
drwxr-xr-x+ 5 Ayman staff 170 Jun 16 15:21 Public
drwxr-xr-x 5 Ayman staff 170 Aug 23 07:57 Sites
Here is my nano .bashprofile:
PS1="\u$ "
alias ll="ls -lahG"
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
Here is my nano .bashrc (I changed it per instructions in another stackoverflow answer):
PATH=$PATH:~/.rvm/bin
Any clue as to what to try next? Thanks!
to force update of rc files:
curl -L https://get.rvm.io | bash -s stable --auto-dotfiles
Mac OS runs .bash_profile but not .bash_rc when you create a new terminal. Move those PATH things into .bash_profile and run again.
As to your second problem, seems you add wrong things into PATH. Add followings into .bash_profile:
PATH=$PATH:$HOME/.rvm/scripts # Add RVM to PATH for scripting
. rvm > /dev/null
In Ruby or in Rails:-
I need to show output from below code formated as it shows in command prompt.
require 'net/ssh'
Net::SSH.start( hostname, username, :password => password ) do|ssh|
result = ssh.exec!('ls -ltr')
puts result
end
Let me know how is it possible?
Command (ls -ltr) is dynamic and
currently output is:
total 257140 drwxrwxr-x 8 folderabc folderabc 4096 Set 4 2010 sources drwxrwxr-x 13 folderabc folderabc 4096 Set 4 2010 teste -rwxrwxr-x 1 folderabc folderabc 72 Set 7 2010 clean_memory -rw-rw-r-- 1 folderabc folderabc 263012352 Mar 17 2011 ngforms_production.sql -rw-rw-r-- 1 folderabc folderabc 21 Jun 23 2011 phps.php drwxrwxr-x 15 folderabc folderabc 4096 Jun 30 2011 ngforms -rw-rw-r-- 1 folderabc folderabc 751 Jul 1 2011 ngforms_word.sql -rw-rw-r-- 1 folderabc folderabc 31 Jul 5 2011 test.php drwxrwxr-x 5 folderabc folderabc 4096 Nov 4 10:52 dump drwxrwxrwx 2 folderabc folderabc 4096 Jan 13 00:00 mysqlbackup
Try using the <pre> tag. Also make sure that the font you use is one of the monospace fonts like CourierNew.
<pre><%= result %></pre>