Using fonts with Rails 4.2.4 Posted: 08 Sep 2016 08:18 AM PDT I'm trying to use a particular font in a Rails 4.2.4 app and nothing is working--it stubbornly refuses to show up. I've spent a few hours on it, and I don't know what I'm doing wrong. The font is located at app/assets/fonts/comic_andy.tff . SCSS (located at app/assets/stylesheets/sass/application.css.scss ): @font-face { font-family: "comic_andy"; src: font-url('comic_andy.ttf'); src: font-url('comic_andy.ttf'), format('truetype'); } In the browser, the SCSS compiles to this CSS: @font-face { font-family: "comic_andy"; src: url(/fonts/comic_andy.ttf); src: url(/fonts/comic_andy.ttf), format("truetype"); } Isn't it supposed to be compiling to assets/comic_andy.ttf? I'm newer to Rails and although I get what the asset pipeline is, it's still proving tricky to wrap my head around enough to use very efficiently. I've read through Rails 4 - Custom Fonts, How to use fonts in Rails 4 and several other Stack Overflow questions related to fonts/Rails/the asset pipeline, and tried many of the suggestions, including (but not limited to!) adding config.assets.paths << Rails.root.join('app', 'assets', 'fonts') to application.rb (nope), trying asset-url (nope), font-url (nope), and plain url (nope), and restarting the server several times after rake assets:clobber (nope). :( |
RAILS : NameError on Debian but not on Mac OS Posted: 08 Sep 2016 08:22 AM PDT I have a rails app, it works perfectly on mac os with no errors (in development). Recently i switch to my debian laptop, and i have a lot of name errors with my app (always in development). For example i have a model named User, in this model (in a method) i call a class method of another model (Participant), no problems on mac os, but on debian i have NameError in Users#show uninitialized constant User::Participant I dont understand why .. Thank you a lot |
gem install Sqlite3 erroring out Posted: 08 Sep 2016 08:14 AM PDT I'm trying to configure an environment to run rails on Windows 7 and I just can't seem to get sqlite3_native working to run "rails server". I have followed the steps at: How do I install sqlite3 for Ruby on Windows? All the way to step 8, where I am failing. I run the command: gem install sqlite3 --platform=ruby -- --with-sqlite3-include=C:\RDK64\sqlite3\ --with-sqlite3-lib=C:\RDK64\sqlite3.libs\ And where that should successfully generate the ruby gem, instead I get this output: C:\Users\owner\repo\cis467>gem install sqlite3 --platform=ruby -- --with-sqlite3 -include=C:\RDK64\sqlite3\ --with-sqlite3-lib=C:\RDK64\sqlite3\.libs\ Temporarily enhancing PATH to include DevKit... Building native extensions with: '--with-sqlite3-include=C:\RDK64\sqlite3\ --wit h-sqlite3-lib=C:\RDK64\sqlite3\.libs\' This could take a while... ERROR: Error installing sqlite3: ERROR: Failed to build gem native extension. current directory: C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/sqlite3-1.3.11/ext /sqlite3 C:/Ruby23-x64/bin/ruby.exe -r ./siteconf20160908-69352-ouc8rr.rb extconf.rb --wi th-sqlite3-include=C:\RDK64\sqlite3\ --with-sqlite3-lib=C:\RDK64\sqlite3\.libs\ checking for sqlite3.h... yes checking for sqlite3_libversion_number() in -lsqlite3... yes checking for rb_proc_arity()... yes checking for rb_integer_pack()... yes checking for sqlite3_initialize()... yes checking for sqlite3_backup_init()... yes checking for sqlite3_column_database_name()... no checking for sqlite3_enable_load_extension()... yes checking for sqlite3_load_extension()... yes checking for sqlite3_open_v2()... yes checking for sqlite3_prepare_v2()... yes checking for sqlite3_int64 in sqlite3.h... yes checking for sqlite3_uint64 in sqlite3.h... yes creating Makefile To see why this extension failed to compile, please check the mkmf.log which can be found here: C:/Ruby23-x64/lib/ruby/gems/2.3.0/extensions/x64-mingw32/2.3.0/sqlite3-1.3.11/ mkmf.log current directory: C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/sqlite3-1.3.11/ext/sql ite3 make "DESTDIR=" clean current directory: C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/sqlite3-1.3.11/ext/sql ite3 make "DESTDIR=" compiling backup.c In file included from backup.c:3:0: ./sqlite3_ruby.h:32:21: fatal error: sqlite3.h: No such file or directory compilation terminated. make: *** [backup.o] Error 1 make failed, exit code 2 Gem files will remain installed in C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/sqlite 3-1.3.11 for inspection. Results logged to C:/Ruby23-x64/lib/ruby/gems/2.3.0/extensions/x64-mingw32/2.3.0 /sqlite3-1.3.11/gem_make.out The mkmf file read as follows: find_header: checking for sqlite3.h... -------------------- yes "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lx64-msvcrt-ruby230 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: int main(int argc, char **argv) 6: { 7: return 0; 8: } /* end */ "x86_64-w64-mingw32-gcc -E -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -o conftest.i" checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: #include <sqlite3.h> /* end */ -------------------- find_library: checking for sqlite3_libversion_number() in -lsqlite3... -------------------- yes "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " conftest.c: In function 't': conftest.c:16:57: error: 'sqlite3_libversion_number' undeclared (first use in this function) conftest.c:16:57: note: each undeclared identifier is reported only once for each function it appears in checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: int t(void) { void ((*volatile p)()); p = (void ((*)()))sqlite3_libversion_number; return !p; } /* end */ "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: extern void sqlite3_libversion_number(); 17: int t(void) { sqlite3_libversion_number(); return 0; } /* end */ -------------------- have_func: checking for rb_proc_arity()... -------------------- yes "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lsqlite3 -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_proc_arity; return !p; } /* end */ -------------------- have_func: checking for rb_integer_pack()... -------------------- yes "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lsqlite3 -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_integer_pack; return !p; } /* end */ -------------------- have_func: checking for sqlite3_initialize()... -------------------- yes "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lsqlite3 -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " conftest.c: In function 't': conftest.c:16:57: error: 'sqlite3_initialize' undeclared (first use in this function) conftest.c:16:57: note: each undeclared identifier is reported only once for each function it appears in checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: int t(void) { void ((*volatile p)()); p = (void ((*)()))sqlite3_initialize; return !p; } /* end */ "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lsqlite3 -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: extern void sqlite3_initialize(); 17: int t(void) { sqlite3_initialize(); return 0; } /* end */ -------------------- have_func: checking for sqlite3_backup_init()... -------------------- yes "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lsqlite3 -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " conftest.c: In function 't': conftest.c:16:57: error: 'sqlite3_backup_init' undeclared (first use in this function) conftest.c:16:57: note: each undeclared identifier is reported only once for each function it appears in checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: int t(void) { void ((*volatile p)()); p = (void ((*)()))sqlite3_backup_init; return !p; } /* end */ "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lsqlite3 -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: extern void sqlite3_backup_init(); 17: int t(void) { sqlite3_backup_init(); return 0; } /* end */ -------------------- have_func: checking for sqlite3_column_database_name()... -------------------- no "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lsqlite3 -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " conftest.c: In function 't': conftest.c:16:57: error: 'sqlite3_column_database_name' undeclared (first use in this function) conftest.c:16:57: note: each undeclared identifier is reported only once for each function it appears in checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: int t(void) { void ((*volatile p)()); p = (void ((*)()))sqlite3_column_database_name; return !p; } /* end */ "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lsqlite3 -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " C:\Users\owner\AppData\Local\Temp\ccHlMUDB.o: In function `t': C:\Ruby23-x64\lib\ruby\gems\2.3.0\gems\sqlite3-1.3.11\ext\sqlite3/conftest.c:17: undefined reference to `sqlite3_column_database_name' collect2.exe: error: ld returned 1 exit status checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: extern void sqlite3_column_database_name(); 17: int t(void) { sqlite3_column_database_name(); return 0; } /* end */ -------------------- have_func: checking for sqlite3_enable_load_extension()... -------------------- yes "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lsqlite3 -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " conftest.c: In function 't': conftest.c:16:57: error: 'sqlite3_enable_load_extension' undeclared (first use in this function) conftest.c:16:57: note: each undeclared identifier is reported only once for each function it appears in checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: int t(void) { void ((*volatile p)()); p = (void ((*)()))sqlite3_enable_load_extension; return !p; } /* end */ "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lsqlite3 -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: extern void sqlite3_enable_load_extension(); 17: int t(void) { sqlite3_enable_load_extension(); return 0; } /* end */ -------------------- have_func: checking for sqlite3_load_extension()... -------------------- yes "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lsqlite3 -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " conftest.c: In function 't': conftest.c:16:57: error: 'sqlite3_load_extension' undeclared (first use in this function) conftest.c:16:57: note: each undeclared identifier is reported only once for each function it appears in checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: int t(void) { void ((*volatile p)()); p = (void ((*)()))sqlite3_load_extension; return !p; } /* end */ "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lsqlite3 -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: extern void sqlite3_load_extension(); 17: int t(void) { sqlite3_load_extension(); return 0; } /* end */ -------------------- have_func: checking for sqlite3_open_v2()... -------------------- yes "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lsqlite3 -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " conftest.c: In function 't': conftest.c:16:57: error: 'sqlite3_open_v2' undeclared (first use in this function) conftest.c:16:57: note: each undeclared identifier is reported only once for each function it appears in checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: int t(void) { void ((*volatile p)()); p = (void ((*)()))sqlite3_open_v2; return !p; } /* end */ "x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Ruby23-x64/include/ruby-2.3.0/x64-mingw32 -IC:/Ruby23-x64/include/ruby-2.3.0/ruby/backward -IC:/Ruby23-x64/include/ruby-2.3.0 -I. -IC:\RDK64\sqlite3\ -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L. -LC:/Ruby23-x64/lib -LC:\RDK64\sqlite3\.libs\ -L. -lsqlite3 -lx64-msvcrt-ruby230 -lsqlite3 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi " checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: 6: /*top*/ 7: extern int t(void); 8: int main(int argc, char **argv) 9: { 10: if (argc > 1000000) { 11: printf("%p", &t); 12: } 13: 14: return 0; 15: } 16: extern void sqlite3_open_v2(); 17: int t(void) { sqlite3_open_v2(); return 0; } /* end */ -------------------- I trimmed some of this to allow the post. I will provide the rest in a comment. |
Rails Ajax PUT Request Posted: 08 Sep 2016 08:02 AM PDT I'm trying to submit a form by Ajax using the form_for :remote option. But I'm getting an error: ActionController::RoutingError (No route matches [POST] "/auctions/2/bids/28/purchase_confirmation") I believe it is a problem with my routes The route is put 'update_order/:transaction' => 'transactions#deduct_shipping_cost', as: "deduct_shipping_cost" Which makes me think the form is not getting sent to the correct route because its's saying a POST does not exist. Here's the form .form-container = form_for(deduct_shipping_cost_path, html: { class: "inline-form" }, remote: true) do |f| .field.form-group.freight_num = f.text_field :shipping_account, class: "form-control", placeholder: "Account #" .actions.freight_num.send_ship_num{style: "margin-bottom: 20px;"} = f.submit 'Submit', class: "btn custom-btn" |
Ruby keeps telling me my file does not exist Posted: 08 Sep 2016 08:09 AM PDT I'm trying to check if a file exists with RoR but it keeps saying this file does not exist and I can't understand why. if File.exist?('~/Desktop/test.xls') p 'File EXISTS' else p 'Cannot find any file' end Of course the file exists and I can access it with the terminal using 'ls'. The script is into the scripts folder of my rails app. Thanks for any help |
ruby gsub new line characters Posted: 08 Sep 2016 08:05 AM PDT I have a string with newline characters that I want to gsub out for white space. "hello I\r\nam a test\r\n\r\nstring".gsub(/[\\r\\n]/, ' ') something like this ^ only my regex seems to be replacing the 'r' and 'n' letters as well. the other constraint is sometimes the pattern repeats itself twice and thus would be replaced with two whitespaces in a row, although this is not preferable it is better than all the text being cut apart. If there is a way to only select the new line characters. Or even better if there a more rubiestic way of approaching this outside of going to regex? |
In Rails, having trouble running a cron job Posted: 08 Sep 2016 07:48 AM PDT I'm using Rails 4.2.7. I want to schedule a service method I've written to execute every day at a particular time, so I decided to try Rails "whenever" gem. In my Gemfile I have gem 'whenever', :require => false I created a file config/schedule.rb and added every 1.day, :at => '9:17 am' do runner "RunCrawlersService.run_all_crawlers" end but at the designated time, nothing happens. Here is my app/services/run_crawlers_service.rb file class RunCrawlersService def run_all_crawlers … end end What else do I need to do to run this thing at the specified time? |
Rails - Good file manager for uploading files? Posted: 08 Sep 2016 07:28 AM PDT aloha. i'd like to ask you if you have any good recommendations regarding a good file manager. if it's good i'd be happy if it's comfortable with rails but i guess i can't prevent using jquery so that's fine too. i'm using bootstrap so if there's something comfortable out there i won't mind either. but what i'm really looking for: - drag and drop
- simple and minimalistic
- somehwat responsie as much file manager can be responsive
- filtering data-types like i wan't just specific types of data so some kind of validation maybe
- it can be used with javascript (drag and drop) and can be used if user have javascript turned off (manually uploading it over files)
- progress bar is a nice feature to have
is there something you can recommend? maybe something what's popular and good maintained? i'd love to try it out and would be really glad about any tips you have right there. cheers! |
Action Cable: Notify a single user Posted: 08 Sep 2016 07:25 AM PDT I am building a chat application in which users can chat privately. I am stuck at the following point: - 'User A' clicks on 'User B' s chat icon, now we need to send a notification to a single 'User B'. How can one achieve this?
- 'User A' has N number of friends. When 'User A' goes offline, how do one notify only the N number of friends in the system?
So in general, how to send a notification to a limited number of connected users? |
Rails redirect back to root with Bootstrap-tour Posted: 08 Sep 2016 07:27 AM PDT I just pushed my RoR application to my staging server and am seeing some odd behavior when I go to a page... it loads then redirects me back to my root_path! This is not the behavior I am seeing in my localhost development environment, which is making it hard for me to debug. I'm hoping someone has seen this type of issue before and/or has some suggestions on how to fix... I'm navigating to NetworkHosts#show : class NetworkHostsController < ApplicationController before_action :set_network_host, only: [:show] before_action :get_company_and_locations def show @network_host = NetworkHost.find(params[:id]) if @network_host @major_issues = get_host_issues(@network_host, @network_host.last_test, "major") @minor_issues = get_host_issues(@network_host, @network_host.last_test, "minor") end end private def set_network_host @network_host = NetworkHost.find(params[:id]) end end The before_action :set_company_and_locations method is in application_helper.rb def get_company_and_locations @company = current_user.company @devices = Device.where(company_id: @company.id).order(name: :asc) @locations = if @company current_user.company_locations.order(:name) else [] end end NetworkHostsController#show loads, but then redirects me right back to my root path. I don't have a redirect reference in the controller method, so the behavior I'm seeing doesn't make sense. Here is what I'm seeing in my log file: [2016-09-08T08:52:05.731929 #24533] INFO -- : Started GET "/network_hosts/61" for 102.12.33.232 at 2016-09-08 08:52:05 -0500 I, [2016-09-08T08:52:05.736988 #24533] INFO -- : Processing by NetworkHostsController#show as HTML I, [2016-09-08T08:52:05.737089 #24533] INFO -- : Parameters: {"id"=>"61"} I, [2016-09-08T08:52:05.758847 #24533] INFO -- : Rendered layouts/_back_button.html.erb (0.4ms) I, [2016-09-08T08:52:05.775550 #24533] INFO -- : Rendered layouts/_network_host_modal.html.erb (1.4ms) I, [2016-09-08T08:52:05.779707 #24533] INFO -- : Rendered network_hosts/show.html.erb within layouts/application (21.4ms) I, [2016-09-08T08:52:05.780110 #24533] INFO -- : Rendered layouts/_google_analytics.html.erb (0.1ms) I, [2016-09-08T08:52:05.795524 #24533] INFO -- : Rendered layouts/_navigation.html.erb (14.9ms) I, [2016-09-08T08:52:05.796621 #24533] INFO -- : Rendered layouts/_topnav.html.erb (0.9ms) I, [2016-09-08T08:52:05.796919 #24533] INFO -- : Rendered layouts/_footer.html.erb (0.1ms) I, [2016-09-08T08:52:05.797293 #24533] INFO -- : Rendered layouts/_tour.html.erb (0.1ms) I, [2016-09-08T08:52:05.797636 #24533] INFO -- : Completed 200 OK in 60ms (Views: 24.8ms | ActiveRecord: 22.7ms | Solr: 0.0ms) I, [2016-09-08T08:52:06.591084 #24536] INFO -- : Started GET "/" for 102.12.33.232 at 2016-09-08 08:52:06 -0500 I, [2016-09-08T08:52:06.593433 #24536] INFO -- : Processing by PagesController#home as HTML I, [2016-09-08T08:52:07.341991 #24536] INFO -- : Rendered pages/home.html.erb within layouts/application (358.4ms) I, [2016-09-08T08:52:07.342596 #24536] INFO -- : Rendered layouts/_google_analytics.html.erb (0.1ms) I, [2016-09-08T08:52:07.357271 #24536] INFO -- : Rendered layouts/_navigation.html.erb (13.8ms) I, [2016-09-08T08:52:07.358451 #24536] INFO -- : Rendered layouts/_topnav.html.erb (1.0ms) I, [2016-09-08T08:52:07.358761 #24536] INFO -- : Rendered layouts/_footer.html.erb (0.1ms) I, [2016-09-08T08:52:07.359163 #24536] INFO -- : Rendered layouts/_tour.html.erb (0.1ms) I, [2016-09-08T08:52:07.359594 #24536] INFO -- : Completed 200 OK in 766ms (Views: 303.2ms | ActiveRecord: 178.1ms | Solr: 0.0ms) Again, this doesn't happen on my localhost, so I'm lost on how to troubleshoot. Thanks! Update With some help, it looks like my Bootstrap-tour javascript which is loaded in the _tour partial is causing the redirect. _tour.html.erb <script> $(document).ready(function(){ $('#tour').click(function() { tour.restart(); }); var tour = new Tour({ steps: [ { path: "/", element: ".tour-step.tour-step-1", title: "<h3>Navigation</h3>", content: "This menu is what you will use to navigate through the results that Neo gives you.", placement: "right" }, { path: "/", element: ".tour-step.tour-step-2", title: "<h3>Home Dashboard</h3>", content: "The Home dashboard is an executive overview of your security results, as well as tons of other useful (high-level) information.", placement: "right" }, { path: "/", element: ".tour-step.tour-step-3", title: "<h3>Locations</h3>", content: "Select a specific location to see what devices and security issues Neo has found on your network.", placement: "right" }, { path: "/", element: ".tour-step.tour-step-4", title: "<h3>Network</h3>", content: "The network view will give you an overall view of all of your network devices across all locations.", placement: "right" }, { path: "/", element: ".tour-step.tour-step-5", title: "<h3>Information</h3>", content: "You'll find Reports, Audit Logs, and Scan History here.", placement: "right" }, { path: "/", element: ".tour-step.tour-step-6", title: "<h3>Settings</h3>", content: "You can control when and how your Neo operates on your network by selecting a specific Neo and adjusting its settings.", placement: "right" }, { path: "/", element: ".tour-step.tour-step-7", title: "<h3>The Dashboard</h3>", content: "This is your dashboard where you'll find quick information to give you an overview of your security layout. <br/><br/> Don't worry if you don't see much yet. Your Neo takes a litte time to collect the information to display.", placement: "bottom" }, { path: "/", element: ".tour-step.tour-step-8", title: "<h3>Profile</h3>", content: "With this dropdown menu, you'll manage your user profile, add a Neo to your account, log out, and be able to get help.", placement: "left" }, { path: "/locations/new", element: ".tour-step.tour-step-9", title: "<h3>Add Your Neo</h3>", content: "Now, to finish up, lets add a Neo to your profile...<br/><br/>You'll need the serial number provided to you and a good name!", placement: "left", } ], backdrop: true, backdropPadding: 10, }); tour.init(); }); </script> |
validates_confirmation_of :password Posted: 08 Sep 2016 07:50 AM PDT I have this code, that works, but I'm not really sure how? It validates passwords but how does it do this? How do the attr_reader and accessor work? And how do the files communicate with each other. What magic is datamapper performing? Here is my user model: require 'data_mapper' require 'dm-postgres-adapter' require 'bcrypt' class User include BCrypt include DataMapper::Resource property :id, Serial property :username, String property :email, String property :password_digest, Text validates_confirmation_of :password attr_reader :password attr_accessor :password_confirmation def password=(password) @password = password self.password_digest = BCrypt::Password.create(password) end end Here is my controller post: post '/sign-up' do new_user = User.create(:username => params[:username], :email => params[:email], :password => params[:password], :password_confirmation => params[:password_confirmation]) session[:user_id] = new_user.id redirect '/welcome' end |
Upload image on ftp using carrierwave Posted: 08 Sep 2016 06:52 AM PDT I implement image upload on ftp using carrierwave, and it is uploading image on ftp successfully. Now problem is that when server is going to upload image on ftp, ftp is asking for authentication as no of times of images,I mean if I upload 2 images, It is going to ask 2 time for authentication. And I dont want to ask authentication while images are uploading. Here is my configuration for ftp: CarrierWave.configure do |config| config.ftp_host = "ftp.hostname.com" config.ftp_port = 21 config.ftp_user = "user_name" config.ftp_passwd = "password" config.ftp_folder = "/folder_name" config.ftp_url = "ftp://ftp.hostname.com/folder_name" config.ftp_passive = false end Thanks in advance. |
Getting ActionViewTemplate error in Heroku but not local rails environment Posted: 08 Sep 2016 07:53 AM PDT I am deploying to Heroku and keep getting an error when loading the form to create a new room ActionView::Template::Error (undefined method 'attractions' for Room) I have added :attractions in permitted params in the RoomsController params.require(:room).permit(:attractions) and this is what the attractions text field looks like in the form <%= form_for @room, html: {multipart: true} do |f| %> <label for="textarea2" style="font-size: 17px; color: #0089ec;">Neighborhood Attractions</label> <%= f.text_area :attractions, autofocus: true, :placeholder => "What tourist attractions are in your city", :class => "materialize-textarea" %> This is the migration created to add the attractions field class AddAttractionsToRoom < ActiveRecord::Migration def change add_column :rooms, :attractions, :text end end and finally in the show page I have this <div class="col m8 offset-m1 s12"> <p class="grey-text"><%= @room.attractions %></p> </div> Does anybody know why this is happening? Thanks UPDATE: So i checked the logs and found the problem is that i made migration errors and rake was aborting before the attractions field is created. Here is the mess i made: first i add a city_limit boolean field class AddAmenitiesToRoom < ActiveRecord::Migration def change add_column :rooms, :city_limit, :boolean end end then for some reason I forgot I had created the city_limit boolean field and instead thought I had a city string field. So I thought I should rename it to city_limit with this migration class ChangeColumnName < ActiveRecord::Migration def change change_column :rooms, :city, :city_limit, 'boolean USING CAST(test_type AS boolean)' end end And finally I decided, you know what, I think I need a city string field after all for geolocation so added another migration class AddAcityToRoom < ActiveRecord::Migration def change add_column :rooms, :city, :string end end Embarrassing, I know. Staying up late coding away is never good. But the problem can be easily fixed by removing this migration, class ChangeColumnName < ActiveRecord::Migration def change change_column :rooms, :city, :city_limit, 'boolean USING CAST(test_type AS boolean)' end end I just dont know if deleting the migration file is a good idea since I have already run rake db:migrate and there are about 10 other migrations after this one so rake db:rollback is not really an option |
GRAPE-ENTITY ARRAYS Posted: 08 Sep 2016 06:37 AM PDT I'm using Grape and Grape-Entity library in Ruby on Rails Project to expose my params from backend. Is any possibility to expose two params values in one entity param? My backend json: {value: '1', value_second: '2'} , but i want to get {values: [1,2]} from my endpoint. |
Testing HTTP DELETE requests Posted: 08 Sep 2016 06:32 AM PDT I'm currently learning ruby on rails and rspec and have come across a problem. I'm trying to test that when I hit the delete button for a shopping cart I created then that cart is deleted. My test is: context "Delete Cart" do Given!(:product){FactoryGirl.create(:product)} Given!(:cart){FactoryGirl.create(:cart)} Given{add_product(product, cart)} Given {get "/"} Given {xhr :post, "/line_items?product_id=#{product.id}"} When {xhr :delete, "/carts/#{cart.id}"} Then {Cart.exists?(cart.id)} end This passes, which it shouldn't since the cart should have been deleted. Any help provided will be greatly appreciated. |
Javascript - applying a price change when adding quantity in a text field Posted: 08 Sep 2016 06:49 AM PDT I'm using a javascript code block to calculate a price change. My app is an events app (using Ruby for back-end) and I need to offer a user the facility to book as many spaces as they wish - within the confines of the number of spaces available. It needs to be as simple as quantity * price My efforts so far simply aren't working. This is my code so far - booking.new.html.erb - <%= simple_form_for [@event, @booking], id: "new_booking" do |form| %> <div class="calculate-total"> <p> Confirm number of spaces you wish to book here: <input type="number" placeholder="1" min="1" value="1"> </p> <p> Total Amount £<span class="total" data-unit-cost="<%= @event.price %>">0</span> </p> </div> <span class="payment-errors"></span> <div class="form-row"> <label> <span>Card Number</span> <input type="text" size="20" data-stripe="number"/> </label> </div> <div class="form-row"> <label> <span>CVC</span> <input type="text" size="4" data-stripe="cvc"/> </label> </div> <div class="form-row"> <label> <span>Expiration (MM/YYYY)</span> <input type="text" size="2" data-stripe="exp-month"/> </label> <span> / </span> <input type="text" size="4" data-stripe="exp-year"/> </div> </div> <div class="panel-footer"> <%= form.button :submit %> </div> <% end %> <% end %> </div> </div> </div> <script type="text/javascript"> $('.calculate-total input').on('keyup', calculateBookingPrice); function calculateBookingPrice() { var unitCost = parseFloat($('.calculate-total .total').data('unit-cost')), numSpaces = parseInt($('.calculate-total .num-spaces').val()), total = (numSpaces * unitCost).toFixed(2); if (isNaN(total)) { total = 0; } $('.calculate-total span.total').text(total); } $(document).ready(calculateBookingPrice) </script> I'm a complete novice at javascript so I fear I'm making some fairly straightforward error(s) which are causing this not to work. Am I not indenting correctly? Am I not 'targeting' the correct id? Do I need to seperate my javascript into a separate .js file? Is there further code required in the controller/model? Here's my model code - booking.rb - class Booking < ActiveRecord::Base belongs_to :event belongs_to :user def total_amount #quantity.to_i * @price_currency.to_money quantity.to_i * strip_currency(event.price) end private def strip_currency(amount = '') amount.to_s.gsub(/[^\D\.]/, '').to_f end end So far, this is how my view looks (styling is out of kilter due to added fields - not corrected as yet) - the total amount simply shows 0(zero) so isn't even reflecting the initial event.price of one space as shown on the event.show view page. How do I rectify all of this? Is there a jQuery option/library which is more straightforward? |
Mongoid + ActiveAdmin + ActiveRecord - unknown context Posted: 08 Sep 2016 06:01 AM PDT I am using Rails 4.2.3 and Ruby 2.2.2 I used activeadmin gem for my admin panel before. All went fine until I've added mongoid gem and create new model including Mongoid::Document. Once after that I run into issue when trying to access any registered model's page at activeadmin part. For example, I have Locations model. Dashboard works fine, but when I trying to access Locations page at admin I got exception saying: "Don't know what context to use for Location". Note that I've even don't trying to register that mongoid model at the admin part, I got this error just due to the fact of adding the mongoid gem. And I do not want this model to be a part of admin panel, I just want to make old models work as they worked before. maybe some workaround exists? |
Get the mapped path for a resource as it is in routes.rb Posted: 08 Sep 2016 06:48 AM PDT TL;DR; Is there a way to get a string with the resource mapping just as it is declared in routes.rb, including params names? Eg.: /resource/:id/nested/:nested_id/deep/:deep_id /resource/:id/nested/:nested_id /resource/:id I need this string and intend to replace the params manually, maybe with a map like {id: 1, nested_id:2, deep_id: 3} Reason I have a integration where I will receive something like: resource:deep_resource, resource_id:1, extra_args: {id: 1, nested_id:2} or resource:nested_resource, resource_id:1, extra_args: {id: 1} or resource:first_level_resource, resource_id:1, extra_args: {} I intend to replace the values in the url and redirect to the given resource. Maybe with a autofill from the extra_args map to the matching params in the url. I don't want to do a lot of if/else to call deep_resource_path(a,b,c) or nested_resource_path(a,b) or first_level_resource_path(a) Note that for the deep resource I need 2 more args(the grandparent id and the parent id). For the nested resource I only need the parent id and for the first_level resource I only need it`s own Id. So, is it possible? Thank you. ps.: I think the map with the args a better option then receive or hard code de full url to redirect for each resource. So, if the url changes in the future, but keep the same params, the redirection can will keep working. |
Rails Routing not passing ID Posted: 08 Sep 2016 06:00 AM PDT In my rails app, my first, I am having issues with finding the right routing. The routing I have does not pass the variable @annotation nor the id. Using <%= link_to 'Annotate', annotate_path(@annotation), :class => "btn btn-default" %> I want to open a page Routes - amongst other, these are the routes I have tried for this resource: resources :annotations do resources :comments get "annotate", on: :member and get "annotations/:id/annotate" => "annotations#annotate", as: 'annotate' The later one opens the page, using url http://localhost:3000/annotations/7/annotate - yet I get an error message like undefined method 'name' for nil:NilClass when using <%= @annotation.name %> In my controller, I have (not complete): private def annotate @annotation = Annotation.find(params[:id]) end How to go about? |
Best way to represent reference data in Active Record Posted: 08 Sep 2016 06:25 AM PDT Lets say I have a Product that can have any amount of attributes... and those attributes are limited to specific options. A product can have (valid options below each): - Color
- Category
- Waterproof
The list could go on. Is there anyway to represent this in active record with a single table? I think it would be ideal to have a single reference data table that looks something like: create_table :attritubes do |t| t.string :name # Red, Blue, Green, Sports, Formal... t.string :field_type # Color, Category, Waterproof... end It would seem like a waste to have a model for every attribute since it doesn't really do much. Is this a case where I have a generic model called Attribute that a product has many of? Or is there a way for active record to differentiate the attributes by a column (making up this syntax): belongs_to :color, class_name: :attribute, where(field_type: 'color') After typing that out, it almost looks like a scope... is that a better way to go? |
Ember 2.7, Rails 5, JSONAPI, Active Model Serializers - counting the number of records in a hasMany relationship Posted: 08 Sep 2016 05:38 AM PDT This idea started with this question. 2 models: class Trail < ApplicationRecord has_many :notes, dependent: :destroy end class Note < ApplicationRecord belongs_to :trail end 2 serializers: class NotesSerializer < ActiveModel::Serializer attributes :id, :note_body belongs_to :trail end class TrailSerializer < ActiveModel::Serializer attributes :id, :name, :notes_count has_many :notes def notes_count object.notes.size end end When calling the route trails/index, this will fire for every Trail, a count query to count the number of 'child' notes for each Trail. Obviously you would have pagination on the /trails/index route, but if your page size is 100 (not unreasonable) this fires 101 queries. Since I'm doing the full stack, I can easily remove that notes_count from the API completely, and instead, do this in the client (EmberJS): app/models/trail.js import DS from 'ember-data'; export default DS.Model.extend({ <...other attributes here...> notes: DS.hasMany('note', { async: true }), // the above relationship already exists, but now // I add the below computed property since I // removed it from the API notesCount: Ember.computed('notes', function() { return `${this.get('notes.length')}`; }) }); This is possible because JSONAPI includes the relationship 'notes' so I can just count its length. My question is: Is this good? Moving the count to the client seems fine to me, since 'notes' will never be very long, but it does mean the client has to do that length calculation on the index route in the client for each trail. So 100 calculations for a page with 100 trails showing. Is the better solution to leave this in the API but have an actual count property on the Trail model (ie. stored in the database) that gets updated every time a note is added or deleted for that trail? Obviously the count might be a little 'stale' sometimes, but that's not a big issue. If you HAD to have this count property in the API would you do (2) or leave it as a calculated attribute in the serializer? |
How to use reload without validations? Posted: 08 Sep 2016 05:02 AM PDT I'm setting up basic tests for a rails app, I'm wondering how the reload function works. Rails generated the basic crud tests, I adapted them to my need, but it seems like the reload function doesn't work. I create a user with valid params, then ask to change its name, but it seems like nothing's updated (output is still name: 'Toto' instead of name: 'Tata'). Here's the code sample, I just followed the basic rspec tutorial, still, nothing gets updated. Any idea why ? context "with valid params" do let(:new_attributes) { {name: 'Tata'} } it "updates the requested creator" do creator = Creator.create! valid_attributes puts creator.id puts new_attributes put :update, :id => creator.id, :creator => new_attributes creator.reload puts creator.name.to_yaml expect(creator.attributes).to include( { "name" => 'Tata' } ) ... |
how can i compress and increase performanceof this loop? Posted: 08 Sep 2016 05:07 AM PDT Ruby on Rails: from URL i want to get a specific value, for that one i am checking whether the url containing that value or not using an array. if it has that value i am splitting url and returning value. @url = 'http://fruits.com/A15/abc1234-apple-w740_h550_q58.jpg' ['apple','banana','grape','butter','honey'].each do |fruit| if (@url.include? fruit) return @url.split(fruit)[1].freeze end end i don't want to loop 5 times.. question is how can i compress this loop. |
How to render partial from controller action (no JS ERB, just user render js: "command_string") Posted: 08 Sep 2016 06:27 AM PDT I know that in a controller action, as a JS response, instead of having a .js.erb template, I can directly run the JS command desired if it isn't too complicated. As an example: respond_to do |format| # Delete the row from the table containing this user format.js{ render js: "$('#delete_#{user.id.to_i}').closest('tr').remove();" } end Note: The controller action needs to be called to perform database operations. This saves me from creating a one line .js.erb file without dirtying my controller code. But when I try to use this to render a partial, I am simply not having any success. For example, in a .js.erb file, I would call it like this: $('#emailform').html("<%= raw j(render partial: 'admin/email_form') %>"); But trying to use such a JS command from the controller doesn't work for me. My guess is that it is a string concatenation issue. Is it possible to do what I want? Is it a good idea to want that in the first place?! |
align label and text field in a same line rails Posted: 08 Sep 2016 05:48 AM PDT I have an html like below where I have 3 text fields and labels for them. <p class='field'> <%= form.label :points %> <%= form.text_field :coupon_code, :class => 'form-control payment-new' %> <%= button_tag "Apply", class: 'btn btn-lg btn-success primary payment-coupon payment-coupon-mobile ',id: 'apcode' %> </p> <p class='field'> <%= form.label :coupon_code %> <%= form.text_field :coupon_code, :class => 'form-control payment-new' %> <%= button_tag "Apply", class: 'btn btn-lg btn-success primary payment-coupon',id: 'apcode' %> </p> <p class='field'> <%= form.label :gift_code %> <%= form.text_field :gift_code, value: nil, :class => 'form-control payment-new' %> <%= button_tag "Apply", class: 'btn btn-lg btn-success primary payment-code',id: '' %> </p> I want the label to come first and then the text field at the same position (CSS). My 3 label names are Points, Coupon Code and Gift Code. I want my all 3 text fields to be at the same space from my label. I am unable to get that. Below is the CSS I am using. .payment-new{ display: inline-block !important; width: 50% !important; } .payment-coupon{ margin-top: -4px; font-size: 16px; border-radius: 4px; margin-left: 55px; padding: 5px; width: 200px; margin-bottom: -5px; } .payment-code{ margin-top: -4px; font-size: 16px; border-radius: 4px; margin-left: 55px ; padding: 5px; width: 200px; margin-bottom: -5px; } Please let me know what I am missing. |
Empty field in ActiveAdmin Ruby on Rails Posted: 08 Sep 2016 04:17 AM PDT I have a form of ActiveAdmin but i cant validate de empty fields, i need show a message or something. My form is: form multipart: true do |f| f.inputs "OrganizaciĆ³n" do f.input :nombre, :label => "Nombre" f.input :descripcion, :label => "DescripciĆ³n" f.input :banner, as: :file, hint: image_tag(f.object.banner.url), label: "Banner" end f.actions end Maybe is necesary edit the controller but i dont know how i can do it I appreciate any cooperation |
Updating 'through' model's attributes when creating new association Posted: 08 Sep 2016 04:18 AM PDT I have three models Post , Product , Mention Product has many Posts through Mentions When I create new association like: product.posts << post I'd like corresponding Mention record to have created_at value the same as post 's created_at . How can I do this? |
How to store data to database in Rails [on hold] Posted: 08 Sep 2016 05:59 AM PDT I have a controller named 'register' with action 'store'. The 'store' method have two instance variable called '@name' and '@age'. And I have a model file named 'person.rb'. Now, How I share the instance variable in controller to model. And how to store data stored in database. |
Select null record through the query string params? Posted: 08 Sep 2016 08:17 AM PDT I have the following code in my javascript file which is filtering the records from my table in rails. var dict = { 'columns' : { 'Sun': 5, 'Rain': [1,2,3] } } which returns "columns%5BSun%5D=5&columns%5BRain%5D%5B%5D=1&columns%5BRain%5D%5B%5D=2&columns%5BRain%5D%5B%5D=3" The above code works however it missing a record where the Rain is null . Is there anyway that I can get that null record like the following in javascript? var dict = { 'columns' : { 'Sun': 5, 'Rain': [1,2,3,null] } } which returns "columns%5BSun%5D=5&columns%5BRain%5D%5B%5D=1&columns%5BRain%5D%5B%5D=2&columns%5BRain%5D%5B%5D=3&columns%5BRain%5D%5B3%5D=" The above code is not working. I want to pass 'null' to Rails to get all NULL records back from ActiveRecord . Thanks in advance. |
Rails 4 Error: ArgumentError - wrong number of arguments Posted: 08 Sep 2016 05:59 AM PDT I am pretty new to rails and currently coding my first application. I created a search to search through my Users (either usernames or tags - using acts_as_taggable_on gem). Following error appears: ArgumentError in UsersController#index wrong number of arguments (0 for 1) User Model # Search def self.search(search) if search where(["username LIKE ?", "%#{search}%"]) elsif searchtags none else all end end # Search Tags def self.searchtags(searchtags) if searchtags tagged_with(["#{searchtags}"], :any => true, :wild => true) else none end end User Controller def index @users = User.search(params[:search]) @tagged_users = User.searchtags(params[:searchtags]) end User Index View = form_tag users_path, :method => 'get' do = text_field_tag :search, params[:search] = submit_tag "Search" = form_tag users_path, :method => 'get' do = text_field_tag :searchtags, params[:searchtags] = submit_tag "Search Tags" - @users.each do |user| = image_tag gravatar_for user if user.use_gravatar == true = image_tag user.avatar_filename.url if user.use_gravatar == false %h2= link_to user.username, user %p= link_to "Favorite", userfavorite_user_path(user, type: "favorite"), method: :get %p= link_to "Unfavorite", userfavorite_user_path(user, type: "unfavorite"), method: :get %p= user.tag_list - @tagged_users.each do |user| = image_tag gravatar_for user if user.use_gravatar == true = image_tag user.avatar_filename.url if user.use_gravatar == false %h2= link_to user.username, user %p= link_to "Favorite", userfavorite_user_path(user, type: "favorite"), method: :get %p= link_to "Unfavorite", userfavorite_user_path(user, type: "unfavorite"), method: :get %p= user.tag_list IMPORTANT!
The error only appears with this piece of code: elsif searchtags none in the User Model, without it everything works fine. I need it though to prevent duplications.
Thanks in advance for your help! |
No comments:
Post a Comment