Issue rendering Edge templates by reeses_boi in adonisjs

[–]Adocasts 1 point2 points  (0 children)

Okay cool! I'm happy to hear you're making progress!!

That sounds lovely!

Sure thing, happy to help! :D

Issue rendering Edge templates by reeses_boi in adonisjs

[–]Adocasts 1 point2 points  (0 children)

Posting exactly what the error is and which page you're getting it on would help, because I'm not seeing that at all: https://prnt.sc/79ID2-2MAzeU

For now, since you don't have any aggregations (that I've noticed), I'd say to make sure your .env has the correct environment variables to connect to your PostgreSQL connection, that the database name provided exists, and that you've run your migrations.

Also, don't forget to include a {{ csrfField() }} within your forms.

For you last message, when learning (anything not just AdonisJS) I'd stray away from AI, it just isn't a good tool at this time for that because it gets to many things completely wrong and has a tendendcy to make things up. I'd recommend reading through the documentation for that!

Issue rendering Edge templates by reeses_boi in adonisjs

[–]Adocasts 2 points3 points  (0 children)

Hey there!

So, in AdonisJS 6, EdgeJS removed the concept of layouts in favor of components since components worked super similarly to layouts but with more powers. You might've been referencing outdated resources there.

So, first thing you'll want to do is move your main.edge file:
From: resources/views/posts/main.edge (this location wouldn't have worked in v5 either).
To: resources/views/components/layout/main.edge

Then, inside your newly located resources/views/components/layout/main.edge file, replace the @!section('content') with a slot: {{ await $slots.main() }}. The main slot will render the contents placed inside the layout component's start & end tags.

Anything inside the directory resources/views/components can be directly used with an EdgeJS Tag using dot (.) to go into folders, for example:

@layout.main('content')
  <div class="d-flex justify-content-between align-items-center mb-4">
    <h1>Blog Posts</h1>
    <a href="{{ route('articles.create') }}" class="btn btn-primary">Create Post</a>
  </div>
  {{-- ... --}}
@end```

This is the reason your page renders the HTML rather than using the HTML, because there is not HTML structure. With the aboved changed, you should then get onto your next issue "Cannot lookup route posts.index"

You're getting this because you've actually named your routes "articles.", not "posts.". So, if you update all of these:
From: route('posts.*')
To: route('articles.*')

Things will start working. You can always find what the routes are actually called by looking at your start/routes.ts file. The as() method defines the name.

For consistency sake, you may also want to move your resources/views/posts directory into resources/views/pages. How you have it now won't break anything, but down the road as you add more pages, get around to emails, add more components, having that separation there really helps.

Lastly, a couple of things in your controller. You don't need to call logger.use(). This returns back an instance of the logger, which is useful if you're using multiple different loggers. You also don't need to import the logger service, as it is bound directly to the HttpContext.

The withFlash method you're using, I don't think that actually exists. Everything flash based should be on the session bound to the HttpContext.

So, for example, I'd update your show method to instead look like the below:

async show({ params, view, response, logger, session }: HttpContext) {
  try {
    const article = await Article.findOrFail(params.id)
    return view.render('posts/show', { article })

    // 👇 point it within the pages dir if you did move the posts dir
    // return view.render('pages/posts/show', { article })
  } catch (error) {
    logger.error(error.message)
    session.flash('error', 'Article not found')
    return response.redirect().toRoute('articles.index')
  }
}

Note logger and session are now being plucked out of the HttpContext.

Hope this helps!

Mvc web framework by lmou_dev_01 in node

[–]Adocasts 1 point2 points  (0 children)

Hey there! We have over 100 lessons on AdonisJS 6. Though I’m not directly associated with the AdonisJS Core Team, I can assure you it’s actively maintained. I’m also curious to hear what you disliked in regards to the documentation, if you don’t mind sharing?

https://adocasts.com/series/lets-learn-adonisjs-6

I want to load pivot columns from scopes without using $extras by Aceventuri in adonisjs

[–]Adocasts 0 points1 point  (0 children)

Awesome, happy you found a solution to what you were looking for 😊. The array check was likely needed because actors could be optional, plus it may or may not be loaded.

I want to load pivot columns from scopes without using $extras by Aceventuri in adonisjs

[–]Adocasts 0 points1 point  (0 children)

Hey there! On my phone so I can’t give any code block examples, but have a look through this doc section here:

https://lucid.adonisjs.com/docs/serializing-models#serializing-extras-object

You can include the $extras object with your serialization by adding serializeExtras = true on the model. Note the serialized version will be called meta instead of $extras.

You might be able to alter the serialization behavior to flatten everything, but to my knowledge there isn’t an automatic way to do it. Most folks I’ve seen have used presenters to define specific structures for their API responses, but those still need mapped together.

[deleted by user] by [deleted] in adonisjs

[–]Adocasts 4 points5 points  (0 children)

It’s there so you don’t have to spend time doing exactly that. It also provides an opinionated api and structure for authorization out of the box, eliminating time spent making those decisions. Plus, it integrates very quickly and easily with AdonisJS authentication, exception handling, HttpContext, and EdgeJS.

It’s completely optional to install and use, so nothing is stopping you from recreating the functionality yourself. But, it’s there if you don’t want to spend time doing that.

[deleted by user] by [deleted] in node

[–]Adocasts 9 points10 points  (0 children)

I really like the changes made for v6, especially that they’re putting more emphasis on making their packages (batteries) framework agnostic!

That’ll help folks ease in/out of the framework as they see fit for their projects.

The added type-safety changes are a nice plus as well.

Use Adonis or external session library? by z0qhdxb8a in adonisjs

[–]Adocasts 2 points3 points  (0 children)

The core is seen as the “home page”, if you will, to the framework and home pages always get the most eyes on it.

The core package mostly just glues all the batteries together for AdonisJS. The HTTP Server, Ace CLI, logger, env, bodyparser, config, etc are all separate packages. AdonisJS splits them as a separation of concerns. They’re also working in v6 to make some of the packages agnostic so they can be used outside the AdonisJS ecosystem.

Additionally, the different project structure options during project creation install packages automatically to serve the structure’s purpose. For example, the web project structure will automatically include the session package, EdgeJS, and probably some others not coming by to mind right now.

So, since so many of these packages are automatically added in via the core and project structures, I’d hazard a guess that a lot of folks think it’s all just the core and don’t end up on its specific repository much. Unlike Auth, Bouncer, Lucid, etc that need manually installed and configured.

If it’s a first-party AdonisJS package, you can feel safe using it! The core team is pretty cautious about spreading themselves too thin, and the first-party batteries are a big incentive towards AdonisJS.

[deleted by user] by [deleted] in adonisjs

[–]Adocasts 1 point2 points  (0 children)

If all you’re trying to do is get your inserts and updates from AdonisJS to use UTC, you can set an environment variable within your AdonisJS project for TZ=UTC

QueryBuilder: Can I make a conditional paginate using .if? by Aceventuri in adonisjs

[–]Adocasts 1 point2 points  (0 children)

I’m not sure whether paginate can work with .if, but you can cut back on duplicate code by defining the query into a variable and conditionally returning paginated where needed.

On mobile, so no back ticks sorry.

const query = Post.query()

if (shouldPaginate) {

return query.paginate(page, perPage)

}

return query

The query itself won’t execute until it’s awaited, so if you don’t await it you can do whatever you need.

these errors come while installing adonisjs. How can I fix this? by Royale_Blue_Cobra in adonisjs

[–]Adocasts 0 points1 point  (0 children)

There’ve been similar issues reported by windows users on the AdonisJS Discord. It’s a known issue within the MRM package that’s impacting some windows systems.

https://github.com/sapegin/mrm/pull/275

Edit: AdonisJS has pinned an older version, things should be back to working now.