Visiting a rails page throws an error - ruby-on-rails

I have a page which shows a list of images and the amount of points added to that image. Locally it works fine, but now I'm trying to get it to work on my server and when I visit the page I get an error,
We're sorry, but something went wrong.
If you are the application owner check the logs for more information
My log shows this,
I, [2015-02-03T06:51:31.352333 #28417] INFO -- : Started GET "/competitions/4" for 82.73.170.71 at 2015-02-03 06:51:31 -0500
I, [2015-02-03T06:51:31.353823 #28417] INFO -- : Processing by CompetitionsController#show as HTML
I, [2015-02-03T06:51:31.353886 #28417] INFO -- : Parameters: {"id"=>"4"}
I, [2015-02-03T06:51:31.364301 #28417] INFO -- : Rendered competitions/show.html.haml within layouts/application (7.8ms)
I, [2015-02-03T06:51:31.364563 #28417] INFO -- : Completed 500 Internal Server Error in 10ms
F, [2015-02-03T06:51:31.366172 #28417] FATAL -- :
ActionView::Template::Error (undefined method `points' for #<Picture:0x007f80f61ca038>):
54: Votes
55: - if signed_in?
56: - if current_user == #competition.user || current_user.administrator? || Time.now.in_time_zone("Amsterdam") <= #competition.deadline
57: = picture.points
58: -# = pluralize(picture.votes.count, "vote" )
59: -# %span
60: -# %div
app/views/competitions/show.html.haml:57:in `block in _app_views_competitions_show_html_haml___3029568455364587805_70095924335640'
app/views/competitions/show.html.haml:44:in `each'
app/views/competitions/show.html.haml:44:in `_app_views_competitions_show_html_haml___3029568455364587805_70095924335640'
the code from my show.html.haml
- if Time.now.in_time_zone("Amsterdam") >= #competition.deadline_signin
- #competition.pictures.shuffle.each do |picture|
.item
= link_to picture do
= image_tag(picture.image_url)
.content
%p
Door:
= picture.user.name
%p.vote
Votes
- if signed_in?
- if current_user == #competition.user || current_user.administrator? || Time.now.in_time_zone("Amsterdam") <= #competition.deadline
= picture.points
-# = pluralize(picture.votes.count, "vote" )
-# %span
-# %div
-# %p
-# \ #{pluralize(picture.votes.count, "" )}
= link_to picture.title, picture, :class => "art-name"
Does anyone see what the problem might be?
edit "showing migration"
20150131130944_add_points_to_pictures.rb
class AddPointsToPictures < ActiveRecord::Migration
def change
add_column :pictures, :points, :integer, default: 0
end
end
And the migration action,
deploy#appsynt:~/wisemonkeys/current$ RAILS_ENV=production bundle exec rake db:migrate
== AddPositionToPictures: migrating ==========================================
-- add_column(:pictures, :position, :integer)
-> 0.0046s
== AddPositionToPictures: migrated (0.0049s) =================================
== AddPointsToPictures: migrating ============================================
-- add_column(:pictures, :points, :integer, {:default=>0})
-> 0.0034s
== AddPointsToPictures: migrated (0.0037s) ===================================

Did you add points on Picture controller at permit (Rails 4)
Or
In Picture model attr_accessible (Rails3)

Related

ArgumentError (Unsupported argument type: 0 (Integer)):

My search form looks for an object in the database based on the address field.
Everything works fine if i search only for the city name, for example Milan, but the search breaks if a select the complete google maps address suggested via maps Api.
For example "metropolitan city of Milan" or some address "Via Paolo Sarpi, Milano, Metropolitan City of Milan, Italy"
I got:
ArgumentError in PagesController#search
Unsupported argument type: 0 (Integer)
app/controllers/pages_controller.rb:14:in `search'
Started GET "/search?search=Via+Paolo+Sarpi%2C+Milano%2C+Metropolitan+City+of+Milan%2C+Italy&start_date=&end_date=&commit=Search" for ::1 at 2020-07-16 15:13:19 +0200
Processing by PagesController#search as HTML
Parameters: {"search"=>"Via Paolo Sarpi, Milano, Metropolitan City of Milan, Italy", "start_date"=>"", "end_date"=>"", "commit"=>"Search"}
Completed 500 Internal Server Error in 243ms (ActiveRecord: 0.0ms | Allocations: 1931)
Im using geocoder, ransack gem and geocomplete script.
schema.rb
t.string "location"
home
<%= form_tag search_path, method: :get do %>
<%= text_field_tag :search, params[:search], placeholder: "Where are you going?", class: "form-control" , id:"autolocation"%>
...
$(function () {
jQuery("#autolocation").geocomplete();
});
page_controller
class PagesController < ApplicationController
...
def search
if params[:search].present? && params[:search].strip !=""
session[:loc_search] = params[:search]
end
....
if session[:loc_search] && session[:loc_search] != ""
*#cars_address = Car.where(active: true).near(session[:loc_search], 5, order:* 'distance')
else
#cars_address = Car.where(active: true).all
end
.....

Rails giving error when using distinct for removing duplicate records

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

Why am I getting "Error 404 not found" in Ruby on Rails?

This is my issue: When I run the command rails server and go to localhost:3000 I get the page "Error 404 not found", so I try to put localhost:3000/home because it is a view but the issues continue. This is the log in the CMD..
C:\Sites\ifurniture>rails s
=> Booting WEBrick
=> Rails 4.2.7.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-08-16 12:45:45] INFO WEBrick 1.3.1
[2016-08-16 12:45:45] INFO ruby 2.2.4 (2015-12-16) [i386-mingw32]
[2016-08-16 12:45:45] INFO WEBrick::HTTPServer#start: pid=192 port=3000
Started GET "/" for ::1 at 2016-08-16 12:45:47 -0500
ActiveRecord::SchemaMigration Load (1.0ms) SELECT "schema_migrations".* FROM
"schema_migrations"
Processing by Refinery::PagesController#home as HTML
Parameters: {"locale"=>:es}
Refinery::Page Load (1.0ms) SELECT "refinery_pages".* FROM "refinery_pages"
WHERE "refinery_pages"."link_url" = ? LIMIT 1 [["link_url", "/"]]
Refinery::Page Load (7.0ms) SELECT "refinery_pages".* FROM "refinery_pages"
WHERE "refinery_pages"."menu_match" = ? ORDER BY "refinery_pages"."id" ASC LIMI
T 1 [["menu_match", "^/404$"]]
Rendered public/404.html (14.0ms)
Filter chain halted as :find_page rendered or redirected
Completed 404 Not Found in 1974ms (Views: 1775.1ms | ActiveRecord: 11.0ms)
Started GET "/home" for ::1 at 2016-08-16 12:46:00 -0500
Processing by Refinery::PagesController#show as HTML
Parameters: {"path"=>"home", "locale"=>:es}
Refinery::Page Load (29.0ms) SELECT "refinery_pages".* FROM "refinery_pages"
INNER JOIN "refinery_page_translations" ON "refinery_page_translations"."refine
ry_page_id" = "refinery_pages"."id" WHERE "refinery_pages"."parent_id" IS NULL A
ND "refinery_page_translations"."locale" IN ('es', 'en') AND "refinery_page_tran
slations"."slug" = 'home' ORDER BY "refinery_pages"."id" ASC LIMIT 1
Refinery::Page Load (0.0ms) SELECT "refinery_pages".* FROM "refinery_pages"
WHERE "refinery_pages"."menu_match" = ? ORDER BY "refinery_pages"."id" ASC LIMI
T 1 [["menu_match", "^/404$"]]
Rendered public/404.html (0.0ms)
Filter chain halted as :find_page rendered or redirected
Completed 404 Not Found in 1475ms (Views: 1207.8ms | ActiveRecord: 29.0ms)
[2016-08-16 12:46:07] INFO going to shutdown ...
[2016-08-16 12:46:07] INFO WEBrick::HTTPServer#start done.
Exiting
This is my routes file..
Rails.application.routes.draw do
# This line mounts Refinery's routes at the root of your application.
# This means, any requests to the root URL of your application will go to Refinery::PagesController#home.
# If you would like to change where this extension is mounted, simply change the
# configuration option `mounted_path` to something different in config/initializers/refinery/core.rb
#
# We ask that you don't use the :as option here, as Refinery relies on it being the default of "refinery"
post '/suscribir' => 'subscribe#create'
mount Refinery::Core::Engine, at: Refinery::Core.mounted_path
end
The pages_Controller.rb code..
module Refinery
class PagesController < ::ApplicationController
include Pages::RenderOptions
include Productos
before_action :find_page, :set_canonical
before_action :error_404, :unless => :current_user_can_view_page?
# Save whole Page after delivery
after_action :write_cache?
# This action is usually accessed with the root path, normally '/'
def home
#posts = Blog::Post.newest_first.live.includes(:comments, :categories)
render_with_templates?
end
# This action can be accessed normally, or as nested pages.
# Assuming a page named "mission" that is a child of "about",
# you can access the pages with the following URLs:
#
# GET /pages/about
# GET /about
#
# GET /pages/mission
# GET /about/mission
#
def show
#productos = Refinery::Productos::Producto.all
if should_skip_to_first_child?
redirect_to refinery.url_for(first_live_child.url) and return
elsif page.link_url.present?
redirect_to page.link_url and return
elsif should_redirect_to_friendly_url?
redirect_to refinery.url_for(page.url), :status => 301 and return
end
render_with_templates?
end
protected
def requested_friendly_id
if ::Refinery::Pages.scope_slug_by_parent
# Pick out last path component, or id if present
"#{params[:path]}/#{params[:id]}".split('/').last
else
# Remove leading and trailing slashes in path, but leave internal
# ones for global slug scoping
params[:path].to_s.gsub(%r{\A/+}, '').presence || params[:id]
end
end
def should_skip_to_first_child?
page.skip_to_first_child && first_live_child
end
def should_redirect_to_friendly_url?
requested_friendly_id != page.friendly_id || (
::Refinery::Pages.scope_slug_by_parent &&
params[:path].present? && params[:path].match(page.root.slug).nil?
)
end
def current_user_can_view_page?
page.live? || authorisation_manager.allow?(:plugin, "refinery_pages")
end
def first_live_child
page.children.order('lft ASC').live.first
end
def find_page(fallback_to_404 = true)
#page ||= case action_name
when "home"
Refinery::Page.find_by(link_url: '/')
when "show"
Refinery::Page.friendly.find_by_path_or_id(params[:path], params[:id])
end
#page || (error_404 if fallback_to_404)
end
alias_method :page, :find_page
def set_canonical
#canonical = refinery.url_for #page.canonical if #page.present?
end
def write_cache?
# Don't cache the page with the site bar showing.
if Refinery::Pages.cache_pages_full && !authorisation_manager.allow?(:read, :site_bar)
cache_page(response.body, File.join('', 'refinery', 'cache', 'pages', request.path).to_s)
end
end
end
end
When I try to deploy all to Heroku, my app crashes and I get "Application Error".... Please help me, I'm a newbie with Ruby on Rails, thanks.
#iFurniture, problem is here, your 'fallback_to_404' is set to true,
so you get always error_404
def find_page(fallback_to_404 = true)
#page ||= ...
#page || (error_404 if fallback_to_404)
end
I suggest you do it like this:
def find_page(fallback_to_404: false)
error_404 if fallback_to_404
#page ||= ...
#page || (error_404 if fallback_to_404)
end
So fallback_to_404 will be false by default and if you want to set it true, just call it like that
find_page(fallback_to_404: true)
Ruby 2 Keyword Arguments
About this:
#page || (error_404 if fallback_to_404)
May be you want ?
fallback_to_404 ? error_404 : #page
Look a litle better.
I would check your before_action :error_404, :unless => :current_user_can_view_page? Maybe remove that code for the time being to see if it can load up, if it does then there is a good chance that the method is set up incorrectly.
i can resolve the issue just running the CMD
bundle exec rake db:seed
thanks for your help.

Getting ActionView::Template::Error error when trying to make Rails Ajax call

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

Rails ActionView::Template::Error on production

I have a Rails 4 app working in development, but when I deploy to a VPS with Capistrano, I get the following error:
INFO -- : Started GET "/" for ***.***.***.*** at 2013-12-20 22:24:28 +0000
INFO -- : Processing by PortalsController#index as HTML
INFO -- : Rendered portals/index.haml within layouts/application (2.9ms)
INFO -- : Completed 500 Internal Server Error in 7ms
FATAL -- :
ActionView::Template::Error (key not found: :params):
1: %h2
2: = link_to "New portal", new_portal_path
3:
4: %h3 Current portals:
5: = render #portals
app/views/portals/index.haml:2:in `_app_views_portals_index_haml___3074475544725108295_70221306145460'
In looking at differences between production.rb and development.rb, I discovered that setting
config.eager_load = false
in production.rb, the error goes away. However, I would like to keep the default setting of config.eager_load set to true. Does anyone have any ideas on why this would be happening?
portals_controller.rb
def index
#portals = Portal.all
end
portals/index.haml
%h2
= link_to "New portal", new_portal_path
%h3 Current portals:
= render #portals
portals/_portal.haml
%p
= link_to portal.name, portal
config/routes.rb
******::Application.routes.draw do
root to: 'portals#index'
resources :portals, shallow: true do
resources :webpages do
resources :documents
end
end
mount Resque::Server, at: "/resque"
end
I'm using unicorn and nginx on the VPS.

Resources