Encountering a Sails.js malfunction while attempting to modify and save a function

Encountering an issue while attempting to set up edit and update functions using Sails.js. The error occurs upon clicking the edit button.

<html>
            <body>
            <table>
            <thead>
            <th>id</th>
            <th>name</th>
            </thead>
            <tbody>
            <% for(var i=0; i<categories.length; i++){ %>
            <tr>
            <td> <%= categories[i].id %> </td>
            <td> <%= categories[i].name %> </td>
            </tr>
            <a href="category/edit?id=<%= categories[i].id %>">Edit</a> //when click on this it should be appeared to edit page. but instead I got an error
            <% } %>
            </tbody>
            </table>
            </body>
            </html>

Link to my controller

View my edit page here

See the routes configuration

Error encountered during the process

Apologies for providing links to images, unsure of how to proceed.

Answer №1

Looks like there might be a few issues in your code that need fixing.

If you want to display your edited page as a view, here are the steps you should follow:

Start by removing all references to '/category/edit' route from the routes configuration file.

Next, update the edit function in your CategoryController to respond with a view and pass the data retrieved from the findOne model method to the response. Replace

res.redirect('/category');

with

res.view({ category : data });

Lastly, modify the category edit view to handle the data provided in the response.

action="/category/update/<%= category.id %>"

If you have any questions, feel free to ask in the comments section below.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to validate the body object when working with Actions2 in sails.js?

Just starting out with sails.js I understand that the inputs object allows actions2 to validate the request parameters. However, how can I access and validate the request body? For example, req.body. I know I can access this from this.req.body, but I was ...

The method JSON.stringify results in an empty curly braces object ´

Trying to extract the value of an event object from Google Chrome (WebRTC framework) has been a challenge for me. My current approach is as follows: yourConnection.onicecandidate = function (event) { console.log("onicecandidate called on my side with ...

Unusual jQuery error notification

Short Receiving Error in syntax, unrecognized expression: [object Object] @ jquery.js:4267 This code snippet is from jQ: Sizzle.error = function( msg ) { throw new Error( "Error in syntax, unrecognized expression: " + msg ); // Line 4267 }; Detaile ...

Struggling to implement Datatables row grouping using ajax is proving to be quite challenging

Is there a way to group rows in a table based on date ranges, using the data from the first column ("Due_Date"), and leveraging the rowGroup extension provided by Datatables? I've tried various solutions found online, such as using the data property ( ...

What makes long polling to an asp.net mvc app necessitate using the POST instead of GET ajax method?

Currently, my team and I are working on replicating a demo app showcased by Steven Sanderson in his SignalR demonstration, specifically focusing on the long polling feature. While the demo is functioning properly, we have encountered an issue when switchin ...

Conflict between jQuery calendar and mootool image slider detected

<script src='<?php echo $fullpath; ?>lib/jquery.min.js'></script> <script src='<?php echo $fullpath; ?>lib/jquery-ui.custom.min.js'></script> <script src='<?php echo $fullpath; ?>fullcal ...

My table elements are automatically being populated with <tr> elements thanks to Javascript

Upon viewing the screenshot: https://i.sstatic.net/Pwv2v.png it is evident that each element is placed within its own tr. My preference is to have each element contained in a td and then wrap everything within a single tr. Here is the updated HTML stru ...

What is the correct way to use variables to reference whether an item is odd or even in an ng-repeat loop?

Is there a way to access the variables $odd and $even within ng-repeat using a variable for reference? Here is what I have attempted: <ng-repeat="item in items" ng-if="$odd">these are odd{{item}}</div> <ng-repeat="item in items" ng-if="$eve ...

Is there a way for me to submit numerous requests to the Game Coordinator at once?

I am currently utilizing the node-globaloffensive library and I am facing an issue where my code is repeating itself and only returning one request back from the gc. My goal is to send multiple requests in order to receive every rank from all users in my d ...

Display inputs based on selections made on the settings page

I'm currently trying to strategize a way for users to navigate to /settings and select certain checkboxes. Then, when they move on to /new, they will only encounter input fields that pertain to the checkboxes checked in /settings. The process of achi ...

Utilizing Reactjs to efficiently transmit name and value to Material UI autocomplete

I am trying to customize the Material UI Autocomplete component. I need to pass name, value and onchange similarly to how it is done for TextField. Can someone please help me achieve this? My current code is not functioning as expected. < ...

Execute a JavaScript file stored in the filesystem using Selenium

Having trouble running a YUI js script using js.executeScript Selenium method. The script is being executed by Selenium Webdriver to simulate a "click" on a hybrid mobile app (the button is in a webview). String IncludeYUI = "script = document.createElem ...

Sketch a line extending from one element to the next

Is there a way to create a styled line that starts from the center of one <td> element and ends at the center of another? I attempted to use the jQuery Connections plugin but it only connects the edges of the elements, not their centers. The plugin ...

Issue with JTSage Datebox timebox in JQuery Mobile: AM/PM Selector not displaying

For a new mobile project that is a Cordova/jQuery Mobile setup, I am using this plugin. Instead of utilizing a constructor called by a script, I'm trying to use it with data-options inline. Below is my input for time: <input id="txtQaTime" type="t ...

Unit testing promises in Angular using Jasmine

My goal is to create a unit test that demonstrates the process of combining two promises using $q.all in Angular, and then confirming that both promises are resolved simultaneously. describe("Application controller", function() { var scope; var ...

Navigating through Javascript Arrays with Conditions to Separate Objects

If we consider a variable called data, can we extract specific items from an array based on the totalaccount value? For instance, before the first occurrence of totalaccount, there are three accounts that I want to retrieve. Similarly, before the final to ...

What should be included in the get/set/destroy functions for a koa-session database instance?

I'm facing an issue with storing the sessions of my Koa app on a mongo DB server. The problem lies in this part of the documentation that I find confusing: https://github.com/koajs/session/blob/master/Readme.md#external-session-stores It mentions th ...

Exploring the depths of MongoDB: How to query nested arrays of objects

I have encountered a challenge while attempting to create a REST API using the provided data. While everything works smoothly on the client side, I'm facing issues with making POST requests to update the 'players' collection in MongoDB. The ...

Only match the character if it is not at the beginning of the line and if another character is not on the

Is there a way to only match the character "=" in a string if it is not at the beginning of a line and no other character, for example "$", appears on the same line? The equal sign should not be at the beginning of a line No other character, such as "$", ...

Exploring the Depths of Angular Reactive Forms with Recursion

Dealing with recursion and form groups app-root.component.html <div [formGroup]="form"> some content <app-root></app-root> </div> Is it possible to implement the same form group and form controls in my recursive structure? For ex ...