Problems running rails db:migrate with rolify - r

Currently trying to install rolify to my rails application
Followed the steps on github and am getting the following error after running rails db:migrate
/home/alex/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rolify-5.2.0/lib/rolify.rb:30: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/home/alex/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3/lib/active_record/associations.rb:1826: warning: The called method `has_and_belongs_to_many' is defined here
rake aborted!
NoMethodError: undefined method `Migration' for ActiveRecord:Module
/mnt/d/linux-docs/projects/code/rails/kream/kream/src/db/migrate/20200511073629_rolify_create_roles.rb:1:in `<main>'
Caused by:
NoMethodError: undefined method `Migration' for ActiveRecord:Module
/mnt/d/linux-docs/projects/code/rails/kream/kream/src/db/migrate/20200511073629_rolify_create_roles.rb:1:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

Within the migration file ammend the version number like so
class RolifyCreateRoles < ActiveRecord::Migration[6.0]
def change
create_table(:roles) do |t|
t.string :name
t.references :resource, :polymorphic => true
t.timestamps
end
create_table(:users_roles, :id => false) do |t|
t.references :user
t.references :role
end
add_index(:roles, [ :name, :resource_type, :resource_id ])
add_index(:users_roles, [ :user_id, :role_id ])
end
end

Related

Foreign Key Mismatched in rails 7.0.4

I'm quite new to rails and have been studying this database migration.
I have created three tables(models) for my practices namely: **clinicstaffs, beds, **and medicalrecords,
I have edited the clinicstaffs primary key to schoolID,
class CreateClinicstaffs < ActiveRecord::Migration[7.0]
def change
create_table :clinicstaffs, id: false do |t|
t.integer :schoolID, null: false, primary_key: true
t.string :type
t.string :firstname
t.string :middlename
t.string :lastname
t.timestamps
end
end
end
and wanted to assign schoolID as a foreign key on the beds table. I used the rails g migration Add_clinicstaffs_To_beds clinicstaffs:references and produced :
class AddClinicstaffsToBeds < ActiveRecord::Migration[7.0]
def change
add_reference :beds, :clinicstaffs, null: false, foreign_key: true
end
end
but after running rake db:migrate it gives me : foreign key mismatch error.
PS C:\Users\ArmbelBernal\Desktop\MedicalRecords> rake db:migrate
== 20221202165814 AddClinicstaffsToBeds: migrating ============================
-- add_reference(:beds, :clinicstaffs, {:null=>false, :foreign_key=>true})
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: foreign key mismatch - "beds" referencing "clinicstaffs"
C:/Users/ArmbelBernal/Desktop/MedicalRecords/db/migrate/20221202165814_add_clinicstaffs_to_beds.rb:3:in `change'
Caused by:
ActiveRecord::StatementInvalid: SQLite3::SQLException: foreign key mismatch - "beds" referencing "clinicstaffs"
C:/Users/ArmbelBernal/Desktop/MedicalRecords/db/migrate/20221202165814_add_clinicstaffs_to_beds.rb:3:in `change'
Caused by:
SQLite3::SQLException: foreign key mismatch - "beds" referencing "clinicstaffs"
C:/Users/ArmbelBernal/Desktop/MedicalRecords/db/migrate/20221202165814_add_clinicstaffs_to_beds.rb:3:in `change'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
is there anyway to fix this? thanks!
=========================================================
Tried to generate a new scaffold secondbeds status:string assessment:string with a clinicstaffs:references
produces:
class CreateSecondbeds < ActiveRecord::Migration[7.0]
def change
create_table :secondbeds do |t|
t.string :status
t.string :assessment
t.references :clinicstaff, null: false, foreign_key: true
t.timestamps
end
and edited this file to:
class CreateSecondbeds < ActiveRecord::Migration[7.0]
def change
create_table :secondbeds do |t|
t.string :status
t.string :assessment
t.references :clinicstaff_schoolID, references: :clinicstaffs, null: false
t.timestamps
end
rename_column :secondbeds, :clinicstaff_schoolID_id, :clinicstaff_schoolID
add_foreign_key :secondbeds, :clinicstaffs, column: 'clinicstaff_schoolID', primary_key: 'schoolID'
end
end
this does not give me error in running rake db:migrate << how can I implement this in a model I have already created? thanks

Could not load type "App\Form\RepeatedType": class does not exist

I upgrade from synfony 4 to 5. Then i try to test my registration page and get this: Could not load type "App\Form\RepeatedType": class does not exist.
What i have try:
composer install --no-dev --optimize-autoloader (i found this online)
The result:
Installing dependencies from lock file
Verifying lock file contents can be installed on current platform.
Package operations: 0 installs, 0 updates, 5 removals
- Removing symfony/web-profiler-bundle (v5.4.8)
- Removing symfony/maker-bundle (v1.42.0)
- Removing nikic/php-parser (v4.13.2)
- Removing doctrine/doctrine-fixtures-bundle (3.4.2)
- Removing doctrine/data-fixtures (1.5.3)
Generating optimized autoload files
composer/package-versions-deprecated: Generating version class...
composer/package-versions-deprecated: ...done generating version class
69 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Run composer recipes at any time to see the status of your Symfony recipes.
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 255
!! Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
!! Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
!! Symfony\Component\ErrorHandler\Error\ClassNotFoundError {#83
!! #message: """
!! Attempted to load class "MakerBundle" from namespace "Symfony\Bundle\MakerBundle".\n
!! Did you forget a "use" statement for another namespace?
!! """
!! #code: 0
!! #file: "D:\cours\symfony\blog\vendor\symfony\framework-bundle\Kernel\MicroKernelTrait.php"
!! #line: 132
!! trace: {
!! D:\cours\symfony\blog\vendor\symfony\framework-bundle\Kernel\MicroKernelTrait.php:132 { …}
!! D:\cours\symfony\blog\vendor\symfony\http-kernel\Kernel.php:386 { …}
!! D:\cours\symfony\blog\vendor\symfony\http-kernel\Kernel.php:786 { …}
!! D:\cours\symfony\blog\vendor\symfony\http-kernel\Kernel.php:128 { …}
!! D:\cours\symfony\blog\vendor\symfony\framework-bundle\Console\Application.php:168 { …}
!! D:\cours\symfony\blog\vendor\symfony\framework-bundle\Console\Application.php:74 { …}
!! D:\cours\symfony\blog\vendor\symfony\console\Application.php:171 { …}
!! D:\cours\symfony\blog\vendor\symfony\runtime\Runner\Symfony\ConsoleApplicationRunner.php:54 { …}
!! D:\cours\symfony\blog\vendor\autoload_runtime.php:35 { …}
!! D:\cours\symfony\blog\bin\console:11 {
!! ›
!! › require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
!! ›
!! arguments: {
!! "D:\cours\symfony\blog\vendor\autoload_runtime.php"
!! }
!! }
!! }
!! }
!! Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
!! Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
!! 2022-05-17T00:33:06+02:00 [critical] Uncaught Error: Class 'Symfony\Bundle\MakerBundle\MakerBundle' not found
!!
Script #auto-scripts was called via post-install-cmd
WEIRD because others forms worked just before (and now they are broken saying: Attempted to load class "MakerBundle" from namespace "Symfony\Bundle\MakerBundle". Did you forget a "use" statement for another namespace?)
composer require symfony/maker-bundle --dev
Now it's working again except for the registration page ("App\Form\RepeatedType": class does not exist.).
It's worth notting that my autocomplet find Symfony\Component\Form\Extension\Core\Type\RepeatedType in the folder.
And sometimes when i clear cache, it crash when optimizing.
Thanks for reading.
In symfony 5 the use statement for RepeatedType is use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
And to use for let's say a password fiel you would type something like:
$builder
->add('password', RepeatedType::class, [
'type' => PasswordType::class,
'required' => false,
'mapped' => false,
'first_options' => ['label' => 'New password'],
'second_options' => ['label' => 'Repeat password'],
]);

How to solve Twig_Error_Runtime in Symfony 3

I have inherited a rather complicated Symfony 3 project (I'm using Laravel mostly nowadays - it's been years since I used Symfony) so this is a bit out of my wheelhouse.
I did a composer update and it built ok.
composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
- Updating twig/twig 1.x-dev (e8555dc => 1445246): Checking out 1445246d8e
Writing lock file
Generating autoload files
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
// Clearing the cache for the dev environment with debug
// true
[OK] Cache for the "dev" environment (debug=true) was successfully cleared.
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets
Trying to install assets as relative symbolic links.
-- -------- ----------------
Bundle Method / Error
-- -------- ----------------
[OK] All assets were successfully installed.
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget
I cleared the cache
php bin/console cache:clear --no-warmup --env local
When I browse to my local development URL, I get:
Whoops, looks like something went wrong.
(4/4) Twig_Error_Runtime
An exception has been thrown during the rendering of a template ("Notice: Undefined offset: 0").
in exception_full.html.twig (line 1)
at Twig_Template->displayWithErrorHandling(array('status_code' => 500, 'status_text' => 'Internal Server Error', 'exception' => object(FlattenException), 'logger' => object(Logger), 'currentContent' => '', 'app' => object(AppVariable)), array('head' => array(object(__TwigTemplate_ed2c7b0206a4a8ba0c01ceb7e7a7f0ba342d3cbf55c912fe1f34e6abd35411c0), 'block_head'), 'title' => array(object(__TwigTemplate_ed2c7b0206a4a8ba0c01ceb7e7a7f0ba342d3cbf55c912fe1f34e6abd35411c0), 'block_title'), 'body' => array(object(__TwigTemplate_ed2c7b0206a4a8ba0c01ceb7e7a7f0ba342d3cbf55c912fe1f34e6abd35411c0), 'block_body')))
in Template.php (line 403)
<snip/>
(3/4) ContextErrorException
Notice: Undefined offset: 0
in Profiler.php (line 23)
at Twig_Extension_Profiler->enter(object(Twig_Profiler_Profile))
in ProfilerExtension.php (line 40)
<snip/>
(2/4) Twig_Error_Runtime
An exception has been thrown during the rendering of a template ("Notice: Undefined offset: 0").
in base.html.twig (line 11)
at Twig_Template->displayBlock('javascripts', array('env' => 'local', 'app' => object(AppVariable)), array('title' => array(object(__TwigTemplate_e199b3b21ccad34239564ea288dce2bfa2f11212622c2c75863848c603e82b70), 'block_title'), 'stylesheets' => array(object(__TwigTemplate_e199b3b21ccad34239564ea288dce2bfa2f11212622c2c75863848c603e82b70), 'block_stylesheets'), 'body' => array(object(__TwigTemplate_888836406c51f4232014f646f747310c541800b61ef418c11fbfcee42a1afe9b), 'block_body'), 'javascripts' => array(object(__TwigTemplate_e199b3b21ccad34239564ea288dce2bfa2f11212622c2c75863848c603e82b70), 'block_javascripts')))
in Environment.php(467) : eval()'d code (line 51)
<snip/>
(1/4) ContextErrorException
Notice: Undefined offset: 0
in Profiler.php (line 23)
at Twig_Extension_Profiler->enter(object(Twig_Profiler_Profile))
in ProfilerExtension.php (line 40)
Since this appears to be an issue with vendor files, I'm not sure where to go from here.
The last error in the logs is
[2018-03-02 15:56:53] request.CRITICAL: Exception thrown when handling an exception (Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Notice: Undefined offset: 0"). at /Projects/myproject/vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception_full.html.twig line 1) {"exception":"[object] (Twig_Error_Runtime(code: 0): An exception has been thrown during the rendering of a template (\"Notice: Undefined offset: 0\"). at /Projects/myproject/vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception_full.html.twig:1, Symfony\\Component\\Debug\\Exception\\ContextErrorException(code: 0): Notice: Undefined offset: 0 at /Projects/myproject/vendor/twig/twig/lib/Twig/Extension/Profiler.php:23)"} []
Try to add this line in composer.json
"twig/twig": "2.4.4"
For me worked.
It seems the last updates for twig 2.4.5 had this problem.
I found the answer here:
https://github.com/twigphp/Twig/issues/2627

grunt-contrib-connect error :middleware undefined

I am using yeoman's angular generator for my AngularJS app. This generator includes grunt and grunt-contrib-connect, which are very useful... but the dependencies are outdated, so I decided to update those.
When doing so, I have an error for grunt-contrib-connect, here it is when I use the --verbose option:
Running "connect:test" (connect) task
Verifying property connect.test exists in config...OK
File: [no files]
Options: protocol="http", port=9001, hostname="localhost", base=".", directory=null,
keepalive=false, debug=false, livereload=35729, open=false, useAvailablePort=false,
onCreateServer=null, middleware=undefined
Warning: undefined is not a function Use --force to continue.
Aborted due to warnings.
So it seems that the middleware is responsible for this issue, here it is:
middleware: function (connect) {
return [
connect.static('.tmp'),
connect.static('test'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect.static(appConfig.app)
];
}
Any assistance to help me figuring this out is more than welcome :)
Using grunt-contrib-connect version 0.10.1 seemed to solve this issue for me. Issue 161 may be related.

ActiveRecord 3.1 & SQL Exception on Debian

developing on Lion, packaged with sqlite3 3.7.5, i am having no problems.
i pushed to production (Debian Lenny w/ sqlite3 3.5.9) and i get the following SQL Exceptions
SQLite3::SQLException: no such column: taggings.tag_id: [query here]
i confirmed this by running the query manually from the rails dbconsole, and indeed sqlite 3.7.x returns results, but 3.5.x throws an error.
i am confident the query is fine, so is ActiveRecord 3.1 not compatible with sqlite 3.5? I am not seeing a newer version.
any ideas here?
Update
the failing query is...
SELECT tags.*, taggings.tags_count AS count
FROM "tags" JOIN (
SELECT taggings.tag_id, COUNT(taggings.tag_id) AS tags_count
FROM "taggings" INNER JOIN work ON work.id = taggings.taggable_id
WHERE (taggings.taggable_type = 'Work' AND taggings.context = 'tags')
AND (taggings.taggable_id IN(SELECT work.id FROM "work" )
)
GROUP BY taggings.tag_id HAVING COUNT(taggings.tag_id) > 0) AS taggings ON taggings.tag_id = tags.id
and my schema is
create_table "taggings", :force => true do |t|
t.integer "tag_id"
t.integer "taggable_id"
t.string "taggable_type"
t.integer "tagger_id"
t.string "tagger_type"
t.string "context"
t.datetime "created_at"
end
add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
create_table "tags", :force => true do |t|
t.string "name"
end
FIX
well i never discovered the problem, but my assumption is that activerecord 3.1 is not compatible with sqlite 3.5.9.
although the last dpkg version for lenny is 3.5.9, i built 3.7.7 from source and it is processing the queries correctly now.

Resources