How to add a new Parameter - ruby-on-rails-4.2

i am still learning ruby on rails.
My first site is running but now i have this problem:
I run rails generate scaffold staat name:string hauptstadt:string einwohner:integer sprache:string
How is the best way for add a param like "test:string" for staat?

Assuming you want to add another column to your database, just run:
rails g migration add_test_to_staats test:string
This will create a migration file under db/migrate
Open it up to make sure it's what you want.
The run bundle exec rake db:migrate
I would also recommend you go through docs that explains this further, here's a link:
http://guides.rubyonrails.org/active_record_migrations.html

Related

creating a simple event in apache-kafka

I am trying to follow the intro example to apache-kafka and i am having a hard time creating a simple event.
when i run the following command inside the project nothing happens:
node producer.js getting-started.properties
this use to work before, but now its not working.
this is the step and guide that I am following: https://developer.confluent.io/get-started/nodejs/#produce-events
any idea what might be wrong?
Looks like the getting-started.properties file doesn't exist.
Creating this is documented in an earlier step: https://developer.confluent.io/get-started/nodejs/#configuration

How to get Node.js to trace ignition within v8? with --trace-ignition

The version of Node.js I used is 10.21.0. I modified BUILD.gn under deps/v8 folder: I set V8_TRACE_IGNITION=true and I rebuilt Node.js using ./configure after that. Then I run "node --trace-ignition xx.js". I expected to trace the ignition's behavior. But it said bad option. I was wondering where I did wrong.
I was wondering where I did wrong.
To get an answer to that, you'd have to describe exactly what you've done, e.g. by posting the patch showing your edits to the file.
That said, modifying BUILD.gn is not necessary to get --trace-ignition to work. Simply use gn args out/<your_output_dir> to edit your build settings as usual, and add v8_enable_trace_ignition = true.

In a Kotlin multi-platform (or JS) project, (how) can one pass custom command line arguments to Node.js?

I'm working on a Kotlin multi-platform project, and I need my JS tests to run on Node.js but with custom command line arguments (specifically I need node to run with the --expose-gc flag, because some tests need to trigger garbage collection).
Looking at the documentation for the Gradle Kotlin JS DSL I didn't find any mention of how to do that; does anyone know whether it's at all possible and how?
Unfortunately can not answer your question directly, but there is some suggestion to help you with reverse engineering.
Let's start from some example. We have Gradle tasks to run our project using webpack's dev server such as browserDevelopmentRun, browserProductionRun (not sure if multi-platform projects have it, but JS projects do). We can add:
println(tasks.named("browserProductionRun").get().javaClass)
to build.gradle.kts to find out the exact class used for this task. When we sync Gradle, it outputs:
org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack_Decorated
Now we know the exact class of this task so we can investigate its API. The auto completion or navigating inside of the KotlinWebpack class helps us to find out that it has a helpful nodeArgs property to configure NodeJS arguments for it, so we can set them, for example:
tasks.named("browserProductionRun", org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack::class).get().nodeArgs.add("--trace-deprecation")
Getting back to your question.
In your case I guess you need to investigate the browserTest task. Let's get some info about it by adding:
println(tasks.named("browserTest").get().javaClass)
to build.gradle.kts - a-ha - it seems to be of the org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest_Decorated type. Let's check what's inside. Open KotlinJsTest.kt somehow - for example by typing its name into the window being opened by CMD + Shift + O (make sure to select "All Places" here) or just by typing its name somewhere in build.gradle.kts and navigating inside it.
The only interesting thing I see inside this open class is the following block:
override fun createTestExecutionSpec(): TCServiceMessagesTestExecutionSpec {
val forkOptions = DefaultProcessForkOptions(fileResolver)
forkOptions.workingDir = npmProject.dir
forkOptions.executable = nodeJs.requireConfigured().nodeExecutable
val nodeJsArgs = mutableListOf<String>()
return testFramework!!.createTestExecutionSpec(
task = this,
forkOptions = forkOptions,
nodeJsArgs = nodeJsArgs,
debug = debug
)
}
So maybe it can work out to create your own extension of this class, override its createTestExecutionSpec method and provide nodeJsArgs as you need inside it. After that you'll be needing to declare another Gradle task to launch tests inside build.gradle.kts which will use this new extended class.

Ecto mutliple repos-- how to ignore one for migrations

I have an app configured
config :my_app,
ecto_repos: [MyApp.Repo, MyApp.LegacyRepo]
MyApp.Repo's migrations are managed by Ecto.
MyApp.LegacyRepo migrations are handled by Rails and error out on mix ecto.migrate
Is there a way to specify "I have two repos, but please ignore the second for migrations"?
Another option is to change your config.exs. Change it to...
config :my_app, ecto_repos: [MyApp.Repo]
According to the ecto.migrate documentation...
The repositories to migrate are the ones specified under the
:ecto_repos option in the current app configuration. However, if the
-r option is given, it replaces the :ecto_repos config.
Not having a MyApp.LegacyRepo in ecto_repos doesn't prevent reads or writes or anything else you'd expect. It just configures the migration task.
You can pass a repo into mix ecto.migrate like this
mix ecto.migrate -r MyApp.Repo
You can update test/test_helper.ex in a phoenix app to only run one repo migrations like this
Mix.Task.run "ecto.migrate", ["-r", "MyApp.Repo", "--quiet"]

The easiest way to develop the Yeoman generator's template itself

Sample situation
I have my own Yeoman generator, which has a folder with "template" of the resulting project.
The generator takes some information from user, interpolates the "template" with the information and then outputs a simple working project.
I want to ensure the "template" is actually working, at least in one positive scenario if not with all combination of inputs. I can write integration tests (which will run the generator with some data and then try to run the resulting code and verify whether all works as expected), but still, that's sometimes too much work and it's inconvenient for trial and error kind of development or some prototyping.
Question
Is there an easy way how to work with the "template" itself, how to run it or use it locally, manually, without the need to run the generator first every time I change a single letter in files of the "template"?
Maybe some sort of build step, which would run the generator for me with some preset data? Is there anything ready in form of npm module? Does a best practice exist?
After running the integration test, you can spawn some commands in the generated project folder and see if those are passing fine.
So far, the best solution I found is to create a script, which:
Creates a temporary sandbox directory.
Performs npm link
Alters the PATH so it does not contain .bin of your local node_modules (this is needed to prevent locally installed Yeoman take precedence over the global one when the script is ran e.g. as npm run develop).
Sets an environment value NON_INTERACTIVE to something truthy.
Runs yo <your generator> in the sandbox directory.
Runs npm start in the sandbox directory to run the freshly generated server code.
Change your generator so it is able to automatically provide some dummy default values for required prompts without default values if process.env.NON_INTERACTIVE is truthy.
Then run the script as:
$ nodemon --watch <directory with your template> --exec <path to your script> --ext js
It's slow, but it works. This way you can develop the template itself and avoid filling the generator every time you need to try out something.

Resources