items show page doesn't render when a user is logged in on rails - ruby-on-rails-5.1

I get the following in my terminal when I click on an item's show link in my rails app:
Started GET "/items/7-water-bottle" for 127.0.0.1 at 2017-10-17
13:00:36
-0700
Processing by ItemsController#show as HTML
Parameters: {"id"=>"7-water-bottle"}
User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` =
2
ORDER BY `users`.`id` ASC LIMIT 1
Item Load (0.2ms) SELECT `items`.* FROM `items` WHERE `items`.`id` =
7 LIMIT 1
Review Load (0.2ms) SELECT `reviews`.* FROM `reviews` WHERE
`reviews`.`item_id` = 7
Rendering items/show.html.haml within layouts/application
Item Load (0.2ms) SELECT `items`.* FROM `items` WHERE `items`.`id` =
0 LIMIT 1
Rendered items/show.html.haml within layouts/application (6.4ms)
Record not found
Rendering public/404.html
Rendered public/404.html (0.5ms)
For some reason it's looking for an item with an id of 0. I don't have this issue when no one is logged in.
If you need more information, let me know.
Thanks!

It looks like the id that you are passing in is a string. Rails is trying to coerce that sting 7-water-bottle into an integer which will return zero (check in your console).
Are you by chance using the friendly_id gem? If so, you should use the Item.friendly.find(params[:id]) which will search by the slug you have defined instead of trying to search by the integer id.
If this is not the case please include more code and context so we can hunt this issue down!

Related

Apollo Client React container add created element to paginated list of elements without refetching

This title is quite confusing, but I will try to explain the best that I can. I have a situation where I am collecting and displaying a list of data elements from the server in React Native. It uses a query that sends a GraphQL parameter to the server to limit the initial request to the first 15 elements.
query GetElements ($count: Int) {
elements (count: $count) {
id
name
tye
}
}
As previously stated, this will query the main list with an initial count of 15 elements.
I have another page of the app that a user can create a new element on the backend using a different GraphQL query.
My question is: Is there a way to easily update the main list of elements to include the newly created element without performing any addition network requests? In other words, I want to be able to simply add the new element to the main list of elements whenever the create command is successful.
The problem is: Apollo's readQuery command on the update proxy will not return to me the appropriate data set to update unless I know the variables that were send with the initial query; this includes the pagination count variable.
You can now define the key for the queries cache store like this:
query AllItems($cursor: String, $limit: Int, $query: String) {
items(cursor: $cursor, limit: $limit, query: $query) #connection(key: "AllItemsQuery") {
count
cursor
has_next
has_prior
data{
...CoreItem
}
}
}
if you would just like to receive the added item, it seems like you want subscriptions :: http://dev.apollodata.com/react/subscriptions.html

Modx Resource List as checkbox for users

Please help, I am stuck with Modx Revo tv input type options.
What I want to achieve is have a checkbox type tv, that displays the resources of a particular parent as checkbox items. So when user checks an item or two, they will be outputted as comma separated values.
Than I will put my tv in a getresources call on the template and it will output some information form the checked resources.
So how do I convert resource list into checkbox options?
The documentation on this is very ambiguous.
Accomplishing this requires some work, but it is not very difficult.
First, create a new Template Variable. Name it whatever you want, for example list_children. Then go to Input Options tab and set Input Type to Checkbox and under Input Option Values enter the following:
#eval return $modx->runSnippet('list_children');
Go to the Output Options tab and select Delimiter in the Output Type dropdown. In the Delimiter textbox write a single comma ,. Apply the Template Variable to your Template of choice and save.
New, create a new Snippet. Name this list_children, or whatever you changed the eval expression to call.
In this snippet, fill in the following:
<?php
$c = $modx->newQuery('modResource');
$c->where(array(
'parent' => 2, // Id to fetch children from
'published' => 1, // Remove this line if you also want to include unpublished resources
'deleted' => 0 // Remove this line if you also want resources that are marked for deletion
));
$c->sortby('menuindex', 'ASC');
$collection = $modx->getCollection('modResource', $c);
$output = array();
foreach ($collection as $v) {
$output[] = $v->get('pagetitle') . '==' . $v->get('id');
}
return implode('||', $output);
I found an alternative way.
Make TV with Input Type Checkbox.
Put #SELECT pagetitle, id FROM modx_site_content WHERE parent=123
!Attn. pay attention on modx_site_content, it needs to reflect MySQL db prefix, which in this case is modx, change 123 to respective parent id.
Change TV output type to Delimiter and coma (,) as delimiter.
Set TV access to respective templates.
Now you can select any or many children of a parent resource which will output their ids as TV output. E.g. let's say our parent 123 had children 33, 34 and 35. In Template variable sections of the resource using the template with access to tv, you will find a checkbox list with children titles. Selecting one or more, e.g. 33 and 35 will output "33,35" in the tv used in chunk.
I found the solution in Modx forums. Lost the link unfortunately.

Pagination on ruby array without sending request to controller

I have a array of arrays in my rails application and it is something like:
#array=[[1, "Mr.X", "developer"], [2, "Mr.Y", "python"]...... [n, "Mr.Z", "ba"]]
I am getting these records on runtime from a different database server by using SQL query not from ActiveRecord. I want to perform pagination on this data and I am using will_paginate/array
#array = #array.paginate(:page => 1, :per_page => 1)
and in my view, I am calling it by:
<%= will_paginate #array%>
It is showing me the data of one record for the first page and links for other pages, however when clicked on next page link, it is giving the error for nil:nil class, as it is again submitting the parameters but this time, the parameters are not appropriate.
I have the final records in #array and I don't want to send the request in backend again and again and I just want to process it on front end only.
Thanks in advance.
Note: I am having different issue, while submitting the form on the post method for first time, my params are
params = <ActionController::Parameters {"utf8"=>"✓", "authenticity_token"=>"EEzvZTAdFAGZ1vOvfeQ/hx7BmDFknC+xHpP4HdhIUncfZDobL1le1vzeanLRdgVFQtKYLGPCgKOfqf5J9+4J2Q==", "check_box_array"=>["ID", "NAME", "ROLE"], "column_value"=>{"ID"=>"", "NAME"=>"", "ROLE"=>""}, "table_name"=>"employee", "column_length"=>"3", "commit"=>"Search", "controller"=>"test", "action"=>"index"}
and here on the controller index action I am running SQL query and fetching data from database not using any model and storing the results into array, which I am passing to view like ` <%= will_paginate #array %>
But while clicking on any page number, it is submitting the parameters as <ActionController::Parameters {"page"=>"2", "controller"=>"test", "action"=>"index"} permitted: false>
and this time, it is not having any query parameters and it is generating the error for nil class
undefined method for nil:NilClass
But I don't want to send the query parameters, I just want to show the data of #array using pagination i.e. on every page just the required data.

Agile Toolkit - OR statement in combination with Model

I have a Model from which I want to select all rows for which 'caller' or 'callee' is a given value for presentation in a Grid.
I have tried lots of different avenues of accomplishing this and cannot get anywhere with it.
I have a working filter on the Grid which narrows down the results by date (starting and ending dates), by status ("ANSWERED","NO_ANSWER"), I can also add conditions for 'caller' and 'callee', but how do I get it to show all rows where either 'caller' or 'callee' is a match to the current $UserID? Basically showing all calls (rows) a user was involved in?
The MySQL query itself is a simple OR construction, but how do I 'feed' it into the Model or the Grid so that it plays nicely with the other filters on the page?
You can use orExpr() method of DSQL to generate SQL for your needs.
For example,
$m = $this->model->debug(); // enable debug mode
$user_id = $this->api->auth->model->id;// currently logged in user ID
$q = $m->_dsql(); // get models DSQL
$or = $q->orExpr(); // initialize OR DSQL object
$or->where('caller', $user_id) // where statements will be joined with OR
->where('callee', $user_id);
// use one of these below. see which one works better for you
$q->where($or); // add condition with OR statements
$q->having($or); // add condition with OR statements
Of course you can write all of this shorter:
$m = $this->model->debug(); // enable debug mode
$user_id = $this->api->auth->model->id;// currently logged in user ID
$q = $m->_dsql(); // get models DSQL
$q->where($q->orExpr()
->where('caller', $user_id)
->where('callee', $user_id)
);

What is the variable that refers to the number of likes on sharepoint 2013?

I want to write a request on the search result request webpart. My request should enables me to retrieve all documents that have the biggest number of likes. There is no variable for the number of likes proposed on the drop list while writing a request , that why I decided to set a refinableInt00 variable and give it the value : LikesCount but it doesn't work? it means that LikesCount doesn't exist as a variable on sharepoint so what is the variable on sharepoint that would enable me to have the number of likes?
You can get the number of likes using the listitem property "Number of Likes"
This is a code from a Sample console application
using (SPSite site=new SPSite("your site URL"))
{
using (SPWeb web=site.OpenWeb())
{
SPList list = web.Lists["Your List Name"];
foreach (SPListItem item in list.Items)
{
//Print the number of likes
Console.WriteLine(item["Number of Likes"].ToString());
}
}
}
I know this is old but I had the same question. The problem is the LikesCount property does not default to Sortable. To fix this:
-Open up Central Administration
-Go to Search Service Application
-Click on Search Schema
-Locate the "LikesCount" property and click edit
-Scroll down to Sortable and change to Yes
-Run a full crawl on your content source
Ratings for list must be enable.
List -> List settings -> Rating settings ->
Allow items in this list to be rated?
yes ? no
and
Which voting/rating experience you would like to enable for this list?
Likes ? Star Ratings
After that you can access likes by "Number of Likes" field name "LikesCount".
"Number of Ratings" field name "RatingCount"

Resources