Here is my controller:
def index
if params[:limit]
#bisacs = Bisac.order(:bisac_code).page(params[:page]).per(params[:limit])
else
#bisacs = Bisac.order(:bisac_code).page(params[:page])
end
end
Here is my view:
<%= paginate #bisacs %>
<%= page_entries_info #bisacs %>
The error is:
undefined local variable or method `model' for #<Kaminari::Neo4j::Paginated:0x007ff2f211bf38>
For the line:
<%= page_entries_info #bisacs %>
What I am missing here?
But page_entries_info works when I am using this in the controller for other methods:
q = "
MATCH (b:Bisac)
WITH b, size((b)<-[:INCLUDED_IN]-()) as wokas_count
RETURN b.bisac_code as bisac_code, b.bisac_value as bisac_value, wokas_count, b.uuid as uuid
ORDER BY b.bisac_code
;"
#result = Neo4j::Session.current.query(q).to_a
if params[:limit]
#result = Kaminari.paginate_array(#result).page(params[:page]).per(params[:limit])
else
#result = Kaminari.paginate_array(#result).page(params[:page])
end
Here is more info about the error from the log file:
Started GET "/bisacs/d1d614a8-3c70-11e5-8eb8-22000b18b199" for 127.0.0.1 at 2015-08-12 12:49:58 -0400
Processing by BisacsController#show as HTML
Parameters: {"id"=>"d1d614a8-3c70-11e5-8eb8-22000b18b199"}
CYPHER 244ms MATCH (result_bisac:`Bisac`) WHERE (result_bisac.uuid = {result_bisac_uuid}) RETURN result_bisac ORDER BY result_bisac.uuid LIMIT {limit_1} | {:result_bisac_uuid=>"d1d614a8-3c70-11e5-8eb8-22000b18b199", :limit_1=>1}
Bisac#wokas 217ms MATCH bisac24319681 WHERE (ID(bisac24319681) = {ID_bisac24319681}) MATCH bisac24319681<-[rel1:`INCLUDED_IN`]-(result_wokas:`Woka`) RETURN count(result_wokas) AS result_wokas | {:ID_bisac24319681=>24319681}
Bisac#wokas 216ms MATCH bisac24319681 WHERE (ID(bisac24319681) = {ID_bisac24319681}) MATCH bisac24319681<-[rel1:`INCLUDED_IN`]-(result_wokas:`Woka`) RETURN count(result_wokas) AS result_wokas | {:ID_bisac24319681=>24319681}
Rendered bisacs/show.html.erb within layouts/application (239.6ms)
Completed 500 Internal Server Error in 707ms
ActionView::Template::Error (undefined local variable or method `model' for #<Kaminari::Neo4j::Paginated:0x007fad5de0ad28>):
18: <%= select_tag :limit, options_for_select([5, 10, 15, 20, 25, 30], selected: params[:limit] || 25) %>
19: <% end %>
20: <%= paginate #wokas %>
21: <%= page_entries_info #wokas %>
22:
23: <table>
24: <thead>
app/views/bisacs/show.html.erb:21:in `_app_views_bisacs_show_html_erb___1469171013071285334_70191290534340'
Rendered /Users/levi/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (5.6ms)
Changed the index method to use paginate_array.
def index
if params[:limit]
#bisacs = Kaminari.paginate_array(Bisac.order(:bisac_code).to_a).page(params[:page]).per(params[:limit])
else
#bisacs = Kaminari.paginate_array(Bisac.order(:bisac_code).to_a).page(params[:page])
end
end
And got the
<%= page_entries_info #bisacs %>
working.
Ok, so the extra information didn't really get me there, but I tried it myself and was able to reproduce the issue. I think it's an issue in the kaminari-neo4j gem. I've just made a pull request with a fix, but in the meantime can you try changing your Gemfile to this:
gem 'kaminari-neo4j', github: 'cheerfulstoic/kaminari-neo4j'
My forked repository has the fixed. Hopefully megorei / dpisarewski will pull it soon if it seems good and release a gem to rubygems so you can change your Gemfile back
Related
I got an strange issue with my experiments with ERB. Here what code do I have:
# cat ./services_lbs2.erb
<%= def renderVip(description, template)
puts "zxc dfg"
end
%>
# locally and remote
Printing: <%= renderVip('123','456') %>
And here what I am getting in the irb:
irb(main):034:0> #template=File.read('./services_lbs2.erb')
=> "<%= def renderVip(description, template)\nputs \"zxc dfg\"\nend\n%>\n# locally and remotely monitored (all externals)\nPrinting: <%= renderVip('123','456') %>\n"
irb(main):035:0> zxc = ERB.new(#template,nil, "-")
=> #<ERB:0x00000000068d4d88 #safe_level=nil, #src="#coding:US-ASCII\n_erbout = String.new; _erbout.concat(( def renderVip(description, template)\nputs \"zxc dfg\"\nend\n).to_s); _erbout.concat \"\\n# locally and remotely monitored (all externals)\\nPrinting: \"\n\n; _erbout.concat(( renderVip('123','456') ).to_s); _erbout.concat \"\\n\"\n; _erbout.force_encoding(__ENCODING__)", #encoding=#<Encoding:US-ASCII>, #frozen_string=nil, #filename=nil, #lineno=0>
irb(main):036:0> zxc.result(binding)
zxc dfg
=> "renderVip\n# locally and remotely monitored (all externals)\nPrinting: \n"
I could not get the output like:
# locally and remotely monitored (all externals)\nPrinting: zxc dfg\n
Why is it so and how it can be fixed?
Thanks!
The return value puts function is nil so in your case, the method will return nil.
So after execution nil is being appended inside the body tag. For this to work change it to
<%
def renderVip(description, template)
"zxc dfg"
end
%>
I have a controller method in which I am crawling data from different websites. I use distinct in query so that duplicate records should not be displayed.
When I add pagination in my view file it gives some error but without pagination it works fine.
Here is my controller method:
def search_results
#search_data = RtaDubai.where(query_string: #topic.title)
.distinct(:query_string).page(params[:page]).order('id desc')
end
Here is my view file pagination code:
<%= will_paginate #search_data %>
Here is the error:
F, [2019-03-06T08:52:03.692939 #106281] FATAL -- : [c72525d9-dcd2- 4e7d-9851-d72f3940ec09] ActionView::Template::Error (PG::SyntaxError:ERROR: syntax error at or near ")"
LINE 1: SELECT COUNT(DISTINCT ) FROM "rta_dubai" WHERE "rta_dubai"."...
: SELECT COUNT(DISTINCT ) FROM "rta_dubai" WHERE "rta_dubai"."query_string" = $1):
F, [2019-03-06T08:53:41.989800 #107285] FATAL -- : [3946d2c4-3fa3-486c-aa48-c5454b54d111] 94: <% end %>
[3946d2c4-3fa3-486c-aa48-c5454b54d111] 95:
[3946d2c4-3fa3-486c-aa48-c5454b54d111] 96: -->
[3946d2c4-3fa3-486c-aa48-c5454b54d111] 97: <%= will_paginate #search_data %>
[3946d2c4-3fa3-486c-aa48-c5454b54d111] 98: -->
[3946d2c4-3fa3-486c-aa48-c5454b54d111] 99:
[3946d2c4-3fa3-486c-aa48-c5454b54d111] 100:
F, [2019-03-06T08:53:41.989829 #107285] FATAL -- : [3946d2c4-3fa3-486c-aa48-c5454b54d111]
F, [2019-03-06T08:53:41.989852 #107285] FATAL -- : [3946d2c4-3fa3-486c-aa48-c5454b54d111]
app/views/sentiment_analysis/search_results.html.erb:97:in `_app_views_sentiment_analysis_search_results_html_erb__418975307880197008
2_38946080'
def search_results
params[:page] ||= 1
#search_data = RtaDubai.where(query_string: #topic.title)
.uniq
.order('id desc')
.paginate(:page => params[:page], :per_page => 30)
end
I’m using Rails 4.2.3. In my “app/controllers/user_objects_controller.rb” controller file, I have defined this method …
def find_totals
respond_to do |format|
#current_user = User.find(session["user_id"])
format.json {
#month_total = UserObject.find_total_by_user_object_month_and_year(session["user_id"], params[:object], params[:month], params[:year])
#year_total = UserObject.find_total_by_user_object_and_year(session["user_id"], params[:object], params[:year])
render :json => {:month => #monthTotal,
:year => #yearTotal }
}
end
end
I’m trying to use Ajax to invoke this method, and so in my “./app/assets/javascripts/user_objects.js.coffee” script, I have
updateTotal = (arg) ->
object = $('#user_object_object').val()
date = $("#datepicker").datepicker('getDate')
day = $('#user_object_day').val()
month = date.getMonth() + 1
year = date.getFullYear()
if (object != "" && day != "")
# Populate the month and year totals
$.ajax
url: "/user_objects/find_totals"
type: 'GET'
data: {month: month, year: year, object: object}
success: (data) ->
alert(data);
$('#month_total').val(data)
$('#year_total').val(data)
error: ->
alert "Something went wrong getting month and year total"
but I always get the error condition. In my Rails server the below log is printed:
D, [2016-02-24T15:42:24.475092 #12929] DEBUG -- :
D, [2016-02-24T15:42:24.475206 #12929] DEBUG -- :
D, [2016-02-24T15:42:24.475236 #12929] DEBUG -- :
D, [2016-02-24T15:42:24.475265 #12929] DEBUG -- :
I, [2016-02-24T15:42:24.475505 #12929] INFO -- : Started GET "/user_objects/find_totals?month=2&year=2016&object=3" for 127.0.0.1 at 2016-02-24 15:42:24 -0600
I, [2016-02-24T15:42:24.475539 #12929] INFO -- : Started GET "/user_objects/find_totals?month=2&year=2016&object=3" for 127.0.0.1 at 2016-02-24 15:42:24 -0600
F, [2016-02-24T15:42:24.500710 #12929] FATAL -- :
ActionView::Template::Error (undefined method `object' for nil:NilClass):
2:
3: <p>
4: <strong>object:</strong>
5: <%= #user_object.object %>
6: </p>
7:
8: <p>
app/views/user_objects/show.html.erb:5:in `_app_views_user_objects_show_html_erb__2677150194333288712_70363943163180'
F, [2016-02-24T15:42:24.500751 #12929] FATAL -- :
ActionView::Template::Error (undefined method `object' for nil:NilClass):
2:
3: <p>
4: <strong>object:</strong>
5: <%= #user_object.object %>
6: </p>
7:
8: <p>
app/views/user_objects/show.html.erb:5:in `_app_views_user_objects_show_html_erb__2677150194333288712_70363943163180'
Anyone know what this error means and how I can fix it?
It looks like Rails is trying to render show.html.erb, which implies that the ajax request is hitting the show action on your UserObjects controller, which would be indicative of incorrect routes.
Check your routes file. Routes are matched in the order they're specified, so if you have resources :user_objects before you have something like get "user_objects/find_totals" ... then Rails will think the "user_objects/find_totals" URL matches to the show action on your UserObjects controller, with an id of find_totals.
undefined method `object' for nil:NilClass
means that #user_object here
<%= #user_object.object %>
is nil. Which makes sense given that #user_object is no where to be found in your controller method/action def find_totals
You will need to set that instance variable somewhere in your controller for it to be available for you in your view
#user_object is nil.
undefined method `object' for nil:NilClass
index.xls.erb
<% #gd = GoodsDelivery.find_all_by_store_location_id(stores.id) %>
<% gd_qty = 0.00 %>
<% for goods_delivery in #gd %>
<% gdl_qty = goods_delivery.goods_delivery_line_items.where(:product_id => prods.id).where(:customer_bill_id => nil).sum(:quantity) %>
<% gd_qty = gd_qty + gdl_qty %><% end %>
<td><%= gd_qty %></td>
I have a code something like this in index.xls.erb file due to some issues i cannot move it into the controller, But in local server it is running properly where as Heroku is my cloud there it is giving error as follows
Error Messege :
Rack::Timeout::RequestTimeoutError: Request ran for longer than 29.989883911185302 seconds.: SELECT SUM("goods_receipt_line_items"."goods_receipt_quantity") AS sum_id FROM "goods_receipt_line_items" WHERE "goods_receipt_line_items"."goods_receipt_id" = 311 AND "goods_receipt_line_items"."product_id" = 133
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1153:in `async_exec' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1153:in `exec_no_cache' /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter
Request timeout error - looking like it's because of your slow database. Try to run your app local and connected to remote database - I think, you'll receive timeout too.
Im trying to find all records that have similar tags to the currently viewed record.
My controller has:
def show
#tattoo =Tattoo.find(params[:id])
tags = #tattoo.style_list.join(", ")
#tattoos = Tattoo.tagged_with(tags, :any => true).limit(6)
end
(bonus points if anyone can tell me how to randomize the order of records in the arrary)
My view just loops through the array.
Anyway, it works almost all the time but I noticed it breaks occasionally and while troubleshooting I found that it breaks when I use tagged_with("jesse smith", :any => true) but it works when I try tagged_with("jason stephan", :any => true) or tagged_with("black ink", :any => true)
So each term has a space in it but for whatever reason 'jesse smith' kills the action.
My console shows that I have a routing error too:
ActionView::Template::Error (No route matches {:action=>"show", :controller=>"tattoos", :member_id=>nil, :id=>#<Tattoo id: 170, description: "", status: "approved", member_id: nil, created_at: "2011-10-25 23:08:17", updated_at: "2011-11-17 16:56:55", file_file_name: "starry-eyed-rabid-squirrelweb.jpg", file_content_type: "image/jpeg", file_file_size: 294782, file_updated_at: "2011-10-25 23:08:17", album_id: nil, position: 116, favorite_count: 0, share_count: 1, file_remote_url: "http://www.jessesmithtattoos.com/wp-content/gallery...">}):
22: <ol class="small_tattoos">
23: <% #tattoos.each do |t| %>
24: <li>
25: <%= link_to image_tag(t.file.url(:tiny),:alt=>"#{t.style_list}, rtattoos, tattoos"), member_tattoo_path(t.member, t) %>
26: </li>
27: <% end %>
28: </ol>
app/views/index/show.html.erb:25:in `block (2 levels) in _app_views_index_show_html_erb___1839804211534816245_69842632179360__4333294961394575926'
app/views/index/show.html.erb:23:in `block in _app_views_index_show_html_erb___1839804211534816245_69842632179360__4333294961394575926'
app/views/index/show.html.erb:11:in `_app_views_index_show_html_erb___1839804211534816245_69842632179360__4333294961394575926'
So why does the one term cause a routing error and not the others?
I guess you have problem with path helper:
member_tattoo_path(t.member, t)
I see in your error description that
:member_id=>nil
So it turns out that tattoo tagged with jesse smith hasn't corresponding association with name 'member', and path helper, which need valid id, throws exception.