0

I have a model Goal with a column content (and id and others). I want to create a goal without writing the usual code needed for CRUD. I need a limited number of goals, and I (the admin) need to control them.

In Django I could use the API from the command line. In rails, how can I create items without going through CRUD?

thebot
  • 249
  • 1
  • 2
  • 10
  • See [`destroy`](https://api.rubyonrails.org/classes/ActiveRecord/Associations/CollectionProxy.html#method-i-destroy), [`destroy_all`](https://api.rubyonrails.org/classes/ActiveRecord/Associations/CollectionProxy.html#method-i-destroy_all). – Sebastián Palma Jul 30 '19 at 20:34

1 Answers1

1

You can use the rails console to run any code you like, including creating objects.

$ rails c
Running via Spring preloader in process 59002
Loading development environment (Rails 5.2.2.1)
[1] pry(main)> Goal.create!(...)
Schwern
  • 153,029
  • 25
  • 195
  • 336
  • I got this... do you know how I can resolve this? ```/Users/home/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require': dlopen(/Users/home/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/x86_64-darwin17/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib (LoadError) Referenced from: /Users/home/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/x86_64-darwin17/readline.bundle Reason: image not found - /Users/home/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/x86_64-darwin17/readline.bundle and so on``` – thebot Jul 30 '19 at 20:49
  • Check out this SO answer: https://stackoverflow.com/a/54287994/6250385 I assume you're on Mac OS X Mojave? – GProst Jul 30 '19 at 20:50