Rails ActionView::Template::Error on production - ruby-on-rails

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.

Related

Unexpected = in haml file after updating Ruby

I am running a rails application (rails: 4.2 and ruby 2.2.3). I am trying to update my ruby to 2.4.4 and have been able to successfully run bundle install. However, when I start the server and go to the home page of my application, I encounter a unexpected = in the application.html.haml file for this line:
= favicon_link_tag 'favicon.ico'
Has anyone here encountered an error like this?
P.S. if this question has been posted before can someone redirect me to it as I cannot find this problem.
%head
%base{:href => "/dashboard"}
%title Title Page
= favicon_link_tag 'favicon.ico'
= stylesheet_link_tag "application", :media => nil
= javascript_include_tag "application"
= csrf_meta_tags
%body{'ng-app'=>'thumper','ng-controller'=>'MainController'}
- if signed_in?
.navbar.navbar-inverse.navbar-fixed-top{:style => 'padding-top:0px;height: 30px;'}
.container
%button.navbar-toggle{"data-target" => ".navbar-collapse", "data-toggle" => "collapse"}
%a.navbar-brand{:href => "/", :target => "_self"}
= image_tag "main_image.png", :style => 'width:65px;', :alt => 'company_name'
.navbar-collapse.collapse
%ul.nav.navbar-nav
%li
%a{:href => "/faq", :target => "_self"}
%i.fa.fa-lightbulb-o
FAQ
%li
This is my initial part of my application.html.haml file. I get the following error:
DEPRECATED: Please use restforce (https://github.com/ejholmes/restforce) instead.
=> Booting Thin
=> Rails 4.2.11 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.7.2 codename Bachmanity)
Maximum connections set to 1024
Listening on localhost:3000, CTRL+C to stop
Started GET "/testpage" for 127.0.0.1 at 2019-03-12 09:32:47 -0500
ActiveRecord::SchemaMigration Load (44.9ms) SELECT `schema_migrations`.* FROM `schema_migrations`
Processing by TestController#foo as HTML
HERE
Rendered test/foo.html within layouts/application (2.9ms)
Completed 500 Internal Server Error in 1964ms (ActiveRecord: 0.0ms)
ExecJS::RuntimeError - SyntaxError: [stdin]:959:20: unexpected =:
app/views/layouts/application.html.haml:7:in `_app_views_layouts_application_html_haml___861496224579637971_70314333220700'
app/lib/cors.rb:12:in `call'
app/lib/cors.rb:12:in `call'
Started POST "/__better_errors/1f18681361fed4ae/variables" for 127.0.0.1 at 2019-03-12 09:32:50 -0500
The web browser looks like this:

Rails Routes Different In Development and Production

I have a route working just fine in my development environment, but for some reason it's not working in production and I can't figure out why.
When I go to http://localhost:3000/api/v1/register_panelist?api_key=ff4a6fa1c975693bedc2122e6943946b in my development environment, it works great.
However, when I go to http://example.com/api/v1/register_panelist?api_key=ff4a6fa1c975693bedc2122e6943946b it does not resolve, and ends up falling to a "page not found" which is the catch all route at the bottom of my routes file.
In my routes.rb file I have this:
constraints(ApiConstraint) do
namespace :api, defaults: {format: 'json'} do
namespace :v1, defaults: {format: 'json'} do
match "register_panelist", to: "appusers#register_panelist", via: 'get'
match "get_surveys", to: "appusers#get_surveys", via: 'get'
end
end
match "api/v1/*path", to: "api/v1/misc#api_not_found_404", via: :all, format: 'json'
end
...
#at the very bottom
match "*path", to: "static_pages#not_found_404", via: :all, format: false #, :constraints => {:format => [:html, :png]}
In my development environment it seems to resolve correctly. But in production it seems to be falling through to the bottom of the routes.rb file.
Any ideas why?
EDIT: Adding Logs:
Production:
production.log — I, [2017-02-12T11:55:31.455331 #27545] INFO -- : Started GET "/api/v1/register_panelist.json?api_key=ff4a6fa1c975693bedc2122e6943946b&country_id=9&birthday_year=1989&birthday_month=2&birthday_day=16&gender=42198&hispanic=42200&zip=10022&state=45700&ethnicity=42215&standard_relationship=42232&standard_education=42243&standard_hhi_us=43511" for 75.100.38.224 at 2017-02-12 11:55:31 +0000
production.log — I, [2017-02-12T11:55:31.606946 #27545] INFO -- : Prod? true
production.log — I, [2017-02-12T11:55:31.607886 #27545] INFO -- : subdomain:
production.log — I, [2017-02-12T11:55:31.607948 #27545] INFO -- : protocol: https://
production.log — I, [2017-02-12T11:55:31.608020 #27545] INFO -- : Prod? true
production.log — I, [2017-02-12T11:55:31.608052 #27545] INFO -- : subdomain:
production.log — I, [2017-02-12T11:55:31.608086 #27545] INFO -- : protocol: https://
production.log — I, [2017-02-12T11:55:31.617812 #27545] INFO -- : Processing by StaticPagesController#not_found_404 as HTML
production.log — I, [2017-02-12T11:55:31.617925 #27545] INFO -- : Parameters: {"api_key"=>"ff4a6fa1c975693bedc2122e6943946b", "country_id"=>"9", "birthday_year"=>"1989", "birthday_month"=>"2", "birthday_day"=>"16", "gender"=>"42198", "hispanic"=>"42200", "zip"=>"10022", "state"=>"45700", "ethnicity"=>"42215", "standard_relationship"=>"42232", "standard_education"=>"42243", "standard_hhi_us"=>"43511", "path"=>"api/v1/register_panelist.json"}
production.log — I, [2017-02-12T11:55:31.636463 #27545] INFO -- : Rendered text template (0.2ms)
production.log — I, [2017-02-12T11:55:31.636883 #27545] INFO -- : Completed 404 Not Found in 19ms (Views: 11.4ms | ActiveRecord: 0.0ms)
Development:
Started GET "/api/v1/register_panelist?api_key=ff4a6fa1c975693bedc2122e6943946b&country_id=9&birthday_year=1989&birthday_month=2&birthday_day=16&gender=42198&hispanic=42200&zip=53593&state=45700&ethnicity=42215&standard_relationship=42232&standard_education=42243&standard_hhi_us=43511" for ::1 at 2017-02-12 05:56:46 -0600
Prod? false
subdomain:
protocol: http://
Processing by Api::V1::AppusersController#register_panelist as JSON
Parameters: {"api_key"=>"ff4a6fa1c975693bedc2122e6943946b", "country_id"=>"9", "birthday_year"=>"1989", "birthday_month"=>"2", "birthday_day"=>"16", "gender"=>"42198", "hispanic"=>"42200", "zip"=>"53593", "state"=>"45700", "ethnicity"=>"42215", "standard_relationship"=>"42232", "standard_education"=>"42243", "standard_hhi_us"=>"43511"}
User Load (18.7ms) SELECT "users".* FROM "users" WHERE "users"."api_key" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["api_key", "ff4a6fa1c975693bedc2122e6943946b"]]
rake routes output from development:
api_v1_register_panelist GET /api/v1/register_panelist(.:format) api/v1/appusers#register_panelist {:format=>"json"}
api_v1_get_surveys GET /api/v1/get_surveys(.:format) api/v1/appusers#get_surveys {:format=>"json"}
and production server:
api_v1_register_panelist GET /api/v1/register_panelist(.:format) api/v1/appusers#register_panelist {:format=>"json"}
api_v1_get_surveys GET /api/v1/get_surveys(.:format) api/v1/appusers#get_surveys {:format=>"json"}
I would guess that there is something in the web server configuration that is usurping the request before it gets passed to Rails (mod rewrite or the like), or that the mount point setting of the Rails execution environment within your web server (e.g. Unicorn in Nginx, Passenger in Apache) , or maybe a piece of middleware that is handled differently by WEBrick and your live server.
Whatever the case, I would start by checking the routes on the server:
rake routes
and make sure they are what you expect. Next, inspect the rails logs and verify that the request is actually being handled by Rails and not being intercepted by the web server or some middleware. If you crank log level up to debug it should give details about exactly how it is handling it. This should at least give you the next step for where to look.
I'm not positive why this works, but it seems I had to update my routes.rb file to call out that line twice - once within the constraints to find the routes in my development environment, and once without to be found in production:
constraints(ApiConstraint) do
namespace :api, defaults: {format: 'json'} do
namespace :v1, defaults: {format: 'json'} do
#find in development
match "register_panelist", to: "appusers#register_panelist", via: 'get'
match "get_surveys", to: "appusers#get_surveys", via: 'get'
end
end
match "api/v1/*path", to: "api/v1/misc#api_not_found_404", via: :all, format: 'json'
end
#find in production
match "api/v1/register_panelist", to: "api/v1/appusers#register_panelist", via: 'get'
match "api/v1/get_surveys", to: "api/v1/appusers#get_surveys", via: 'get'

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.

Visiting a rails page throws an error

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)

rails routing show action nested resources

Yeah the problem is, that I created a nested resource like this:
resources :albums do
resources :elements
end
and the rake routes command displays:
album_element GET /albums/:album_id/elements/:id(.:format) elements#show
So when I am at
.../albums/1
I can head for
.../albums/1/elements
This starts the index action of the elements controller, just fine.
But if I edit the index.html.erb to
<%= link_to 'Show', album_element_path %>
I got an error like this:
Started GET "/albums/1/elements" for 176.221.47.67 at Tue Oct 09 14:25:39 +0200 2012
Processing by ElementsController#index as HTML
Parameters: {"album_id"=>"1"}
Rendered elements/index.html.erb within layouts/application (9.2ms)
Completed 500 Internal Server Error in 123ms
ActionController::RoutingError (No route matches {:controller=>"elements", :action=>"show"}):
app/views/elements/index.html.erb:29:in `_app_views_elements_index_html_erb___13604879__168097178'
app/views/elements/index.html.erb:18:in `each'
app/views/elements/index.html.erb:18:in `_app_views_elements_index_html_erb___13604879__168097178'
app/controllers/elements_controller.rb:7:in `index'
So it says that no route matches ... but I actually have that in my rake routes displayed ?
What am I doing wrong ?
You need to provide the two neccesary arguments for album_element_path:
<%= link_to 'Show', album_element_path(#album, #element) %>

Resources