Rails help message messed up - ruby-on-rails

I used to be able to type rails generate or rails generate model to
get help information for different rails command lines, for some
unknown reason, now if I type rails generate or rails generate model,
it always show me the help message for rails new, what is going on?

This normally happens if you are not in a rails path, so make sure your curfrent terminal / cmd is in a directory with a rails app you can change dirfectory with cd "/putdirectoryhere"

Related

Error Installing importmap on rails application

I am having troubling setting up an existing rails application. I am supposed to set up importmap but it is giving me trouble.
If having trouble viewing the uploaded pic, it says "rails aborted!
Don't know how to build task 'importmap:install'"
Rails error pic
If I run "rails --tasks" importmap:install does show up.
rails --tasks output snippet
As per the attached screenshot of the task list, the actual task name apparently is called app:importmap:install instead of importmap:install.
I'm not sure why that might be the case, though. It seems to me like you might (accidentally?) be working on a Rails engine instead of an actual app?

In what directory / folder do you install Rails Scaffold

I am following the Rails Tutorial. It is starting to generate a scaffold. I just don't know for sure where to pit it. In a subdirectory or right at the root. My hunch is the root. i.e. JimJones$ not JimJones$/work/newapp. The apps can keep[ changing so I would imagine I would install the scaffold at the root. Any help would be greatly appreciated. Thanks, Chris
Your hunch is wrong, you should be in your /newapp directory, assuming that's the name of your app.
If you're not sure where you're at, enter pwd at the command line, and this will
print out your current location. If it ends in /newapp, you're all good.
rails generate scaffold myscaffold creates a set of MVC scaffolds called myscaffold(s), INSIDE your current app. In fact, You shouldn't be able to run rails generate scaffold unless you are inside a rails project.
Scaffolding is specific to Rails applications. First create a new Rails application using rails new appname command. Then move to the appname directory.
Then use scaffolding
rails generate scaffold test
The above command will generate a set of model, database migration for that model, controller, views, and test suites for the resource test
More info on scaffolding : http://guides.rubyonrails.org/command_line.html
You need to be in the rails app directory to use scaffold and the code generated by scaffold will be put in appropriate locations in your rails app directory e.g. model in models directory controller in controllers

Rubymine using generator from rails console

I am currently using Rubymine for ruby on rails development.
After enjoying the console for testing purposes, I want to use the console instead of the build-in Rails Generator for creating new models and such.
But I can't figure out how to use the rails console (Tools | Run Rails Console) for generating -lets say- a new model "user".
rails generate model user name:string
gives me
NameError: undefined local variable or method `string' for main:Object
I think I'm just missing something very basic here but I couldn't come up with a solution by myself after several tries :/
I hope you can help me out.
Greets
If you feel that you really must use the console to do this, you have a few options to get to the system.
You can use backticks.
or
You can use system()
Your command would then look like system("rails generate model user name:string") or it would look like `rails generate model user name:string`
The command you are trying to run is not something that should be run from a ruby console. It is a bash command. The error you are getting is because you are trying to run something that is not ruby in a ruby environment.

Error regarding ActiveAdmin in Ruby on Rails when customizing the menu

Mac OS X 10.7.3 Lion,
Ruby 1.9.2,
Rails 3.2.2,
Sass 3.2.3
Following this tutorial:
http://activeadmin.info/documentation.html
Following this video tutorial
http://www.youtube.com/watch?v=tAxlrHcEg9U
I add the activeadmin gem, run bundle install, then run
rails generate active_admin:install
rails generate active_admin:resource POST
Only after creating the app/admin/posts.rb and trying to run either
db migrate
rails server
fails with the error
uninitialized constant Post NameError
with out that posts.rb file i am able to run the admin interface error free.
I tried moving the sass-rails gem out side of the :assets in my gem file and re-running bundle install as suggested in another question, but to no avail I still have the error
according to the getting started active admin tutorial "Post" is suppose to be a module name so i assume the code above is calling a class method (ActiveAdmin as the class, register as the method) and sending the module as a parameter and the block do end
Regardless the error is implying that RoR doesn't know what Post is. As if it does not exist. Being new to rails i do not know how to navigate well, meaning i do not even know where this ActiveAdmin source file is in order to dig through it for a method Post
Thank you for the consideration and your time, I appreciate it.
The linked tutorial assumes that you have already created a model named Post (and have run rake db:migrate to link it to the database). The purpose of the rails generate active_admin:resource Post command is to tell ActiveAdmin that you want it to consider the Post model in part of what it does.
Historically, you'll see models like Post and User in Rails a lot -- these are the commonly used examples of creating a blogging application (a user can create blog posts).
So, whatever models you have in your application can be registered with ActiveAdmin by replacing Post with the name of your model.
Another note: while generators like this tend to be forgiving, a Post is a model that is defined in post.rb and is linked to a SQL table called posts. Be careful with things like upper- and lower-case, and singular and plurals. In Rails they all fit together in a special way.

Ruby on Rails: rails generate migration is not giving me a new migration, but giving me an app called generate

I typed this into terminal:
rails generate migration CreateAddress
and instead of creating a new migration file, it created the entirety of a naked rails app.
What is wrong here?
The generate script is a Ruby script, so you should just call it with ruby.
Also, you usually want to call that script from the top level of your app, so:
$ ruby script/generate migration CreateAddress
The reason you have your issue is because executing rails simply creates a naked Rails app in your current directory with the first argument as its name. In this case, that's obviously "generate".

Resources