gpt4 book ai didi

jquery - Rails jquery 适用于本地主机,但不适用于 heroku

转载 作者:太空宇宙 更新时间:2023-11-03 16:51:07 25 4
gpt4 key购买 nike

我的 webapp 快要发布了,但是 jquery 不能像我想要的那样工作。

我在 heroku 上遇到了这个错误:

2014-02-03T00:53:41.347687+00:00 app[web.1]:ActionView::MissingTemplate (Missing template studcourses/new,application/new with {:locale=>[:en], :formats=>[:html],:handlers=>[:erb, :builder, :raw, :ruby, :jbuilder]}. Searched in: 2014-02-03T00:53:41.348378+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/abstract_controller/callbacks.rb:18:in `block in process_action' 2014-02-03T00:53:41.349292+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call' 2014-02-03T00:53:41.349292+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call' 2014-02-03T00:53:41.350044+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call' 2014-02-03T00:53:41.350044+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/cache/strategy/local_cache.rb:83:in `call' 2014-02-03T00:53:41.349292+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch' 2014-02-03T00:53:41.348914+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/abstract_controller/base.rb:136:in `process' 2014-02-03T00:53:41.348914+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/journey/router.rb:59:in `each' 2014-02-03T00:53:41.349292+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/journey/router.rb:59:in `call' 2014-02-03T00:53:41.348732+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_controller/metal/params_wrapper.rb:245:in `process_action' 2014-02-03T00:53:41.348732+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/railties/controller_runtime.rb:18:in `process_action' 2014-02-03T00:53:41.349476+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/query_cache.rb:36:in `call' 2014-02-03T00:53:41.349476+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context' 2014-02-03T00:53:41.349292+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/flash.rb:241:in `call' 2014-02-03T00:53:41.349476+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call' 2014-02-03T00:53:41.349292+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call' 2014-02-03T00:53:41.348914+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/journey/router.rb:71:in `block in call' 2014-02-03T00:53:41.349292+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/head.rb:11:in `call' 2014-02-03T00:53:41.349292+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/params_parser.rb:27:in `call' 2014-02-03T00:53:41.349292+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:655:in `call' 2014-02-03T00:53:41.348914+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:48:in `call' 2014-02-03T00:53:41.349864+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 2014-02-03T00:53:41.349864+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call' 2014-02-03T00:53:41.349864+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/rack/logger.rb:38:in `call_app' 2014-02-03T00:53:41.349476+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/cookies.rb:486:in `call' 2014-02-03T00:53:41.349476+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/remote_ip.rb:76:in `call' 2014-02-03T00:53:41.349292+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/conditionalget.rb:25:in `call' 2014-02-03T00:53:41.349476+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' 2014-02-03T00:53:41.349476+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:373:in `_run__3128314251881795976__call__callbacks' 2014-02-03T00:53:41.349476+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in `run_callbacks' 2014-02-03T00:53:41.349864+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call' 2014-02-03T00:53:41.349864+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:25:in `tagged' 2014-02-03T00:53:41.349864+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:67:in `tagged' 2014-02-03T00:53:41.349864+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/rack/logger.rb:21:in `call' 2014-02-03T00:53:41.349476+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/callbacks.rb:27:in `call' 2014-02-03T00:53:41.350044+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/static.rb:64:in `call' 2014-02-03T00:53:41.350044+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/ssl.rb:24:in `call' 2014-02-03T00:53:41.350044+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:511:in `call' 2014-02-03T00:53:41.350044+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:97:in `call' 2014-02-03T00:53:41.349864+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/request_id.rb:21:in `call' 2014-02-03T00:53:41.349864+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/rack/logger.rb:21:in `block in call' 2014-02-03T00:53:41.349476+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call' 2014-02-03T00:53:41.349864+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:67:in `block in tagged' 2014-02-03T00:53:41.350444+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread' 2014-02-03T00:53:41.350444+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'

但在本地主机上它工作正常。 Heroku 不接受 new.js.erb...

我做了很多次

rake assets:precompile

RAILS_ENV=production bundle exec rake assets:precompile

rake assets:clean

RAILS_ENV=production bundle exec rake assets:clean

我的应用程序.js:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require bootstrap
//= require jquery-1.10.2
//= require jquery
//= require jquery.min
//= require jquery.ui.effect.all
//= require jquery_ujs
//= require turbolinks
//= require_tree .
//

Controller :

class StudcoursesController < ApplicationController
before_action :authenticate_student!
before_action :set_student, only: [:kurse]

def cfails
@courses = Course.all
end


def kurse
@cnames = Cname.all
#@studcourses = Studcourse.all
end

def new
@studcourse = Studcourse.new
end

def create
@studcourse = Studcourse.new(studcourse_params)
if !@studcourse.save
render action: 'error'
end
end

def show
if signed_in?
show_signed_in
else
show_not_signed_in
end
end

def show_signed_in
#add methods here
#@students = Student.find(params[:id])
#@studcourses = Studcourse.find(current_student.id)
end

private
# Use callbacks to share common setup or constraints between actions.
def set_student
@student = Student.find(current_student.id)
end

def studcourse_params
params.require(:studcourse).permit(:matrikel, :modulnrpg, :modulnr, :student_id)
end
end

studcourse/kurse.html.erb(第一 View ):

<% require 'open-uri'%>
<% require 'mechanize'%>
<% require 'nokogiri' %>

<%# Anzeigen von den selbst belegten Kursen %>
<%# TODO Info, dass Kurse nicht erfolgreich abgerufen wurden und das PW überprüft werden soll %>
<%# Nur Kurse abrufen, wenn es der erste Login ist %>
<%= link_to 'Neuer Kurs', new_studcourse_path, id: "new_link", remote: true, :class => "btn btn-success btn-sm" %>
</br>
<% if @student.erste_mal %>
....

studcourse/new.js.erb:

$('#new_link').hide().after('<%= j render("form") %>');
$('#new_studcourse').focus();
$('#cancel_button').clickCancelButton();

studcourse/_form.html.erb:

<%= form_for(@studcourse, remote: true, :html => {id: "new_studcourse"}) do |f| %>
<div class="row form-group">
<div class="col-xs-4">
<label class="control-label" for="studcourse_modulnrpg" id="error-message"></label>
<%= f.text_field :modulnrpg, class: "form-control" %>
</div>
<%#= f.hidden_field :modulnr, :value => .at(0..5)%>
<%= f.hidden_field :matrikel, :value => current_student.matrikel %>
<%= f.hidden_field :student_id, :value => current_student.id %>
<div class="col-xs-3 button-group">
<%= f.submit "Speichern", class: "btn btn-primary btn-sm" %>
<%= link_to 'Abbrechen', studcourses_kurse_path, id: "cancel_button", class: "btn btn-default btn-sm" %>
</div>
</div>
<% end %>

studcourse/create.js.erb:

$('#new_studcourse').remove();
$('#new_link').show();
$('tbody').append('<%= j render(@studcourse) %>');
$('#st_<%= @studcourse.id %>').effect("highlight");

the _studcourse.html.erb

<tr id="studcourse_<%= studcourse.id %>">
<td class="success"><%= studcourse.modulnrpg%></td>

<td><% Cname.where(modulnr: studcourse.modulnr).find do |cnn| %>
<%= cnn.modulname %>
<% end %></td>

<%#= link_to "Löschen", studcourse, :class => "btn btn-danger btn-sm", remote: true, method: :delete, data: { confirm: 'Willst du wirklich das Projekt löschen?' } %>
</tr>

studcourse/error.js.erb:

$(".form-group").addClass("has-error");
$("#error-message").html("<%= j @studcourse.errors.full_messages[0] %>");
$("#new_studcourse").effect("shake");

开发.rb

MyHWRWeb::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false

# Do not eager load code on boot.
config.eager_load = false

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# per SMTP mails verschicken
config.action_mailer.delivery_method = :smtp
# smtp einstellungen
config.action_mailer.smtp_settings = {:address => "localhost", :port => 1025}

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

# Raise an error on page load if there are pending migrations
config.active_record.migration_error = :page_load

# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true

#config.force_ssl = true

#config.assets.css_compressor = :yui
#config.assets.js_compressor = :uglify

config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end

生产.rb

MyHWRWeb::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
config.cache_classes = true

# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true

# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = true

#config.assets.paths << Rails.root.join("app", "assets", "fonts")
#config.assets.css_compressor = :yui
#config.assets.js_compressor = :uglify

# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true

# config.assets.precompile += %w(reset.css bootstrap.min.css bootstrap-responsive.min.css font-awesome.css fancybox.css)
# config.assets.precompile += %w(modernizr.js bootstrap.js)
# config.assets.initialize_on_precompile = false

# Generate digests for assets URLs.
config.assets.digest = true

# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'

# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true

# Set to :debug to see everything in the log.
config.log_level = :info

# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]

# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

# Use a different cache store in production.
# config.cache_store = :mem_cache_store

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com"

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# config.assets.precompile += %w( search.js )

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = {:host => 'myhwr.herokuapp.com'}
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
:authentication => :plain,
:address => "smtp.mailgun.org",
:port => 587,
:domain => "*",
:user_name => "*",
:password => "*"
}
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found).
config.i18n.fallbacks = true

# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify

# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
end

路线:

MyHWRWeb::Application.routes.draw do
get "courses/index"
get "studcourses/kurse"
get "studcourses/cfails"
get "courses/impressum"
get "courses/tutorial"
get "courses/about"
get "studcourses/new"
resources :cnames, except: [:show]
get '/cnames/:id', to: 'cnames#index'
resources :courses, except: [:show]
resources :studcourses, except: [:show]
devise_for :students

# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

root 'courses#index'

# Example of regular route:
# get 'products/:id' => 'catalog#view'

# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products

# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end

# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end

# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end

# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable

# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
end

应用.rb

require File.expand_path('../boot', __FILE__)

require 'rails/all'

require "sprockets/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)



module MyHWRWeb
class Application < Rails::Application

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.

# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
config.time_zone = 'Berlin'

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de

config.i18n.enforce_available_locales = true
end
end

最后是 gemfile:

    source 'https://rubygems.org'
ruby '2.0.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'

# Use sqlite3 as the database for Active Record
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end

group :assets do
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier'
gem "twitter-bootstrap-rails"
end

#gem 'jquery-rails', '>= 1.0.12'

# Use SCSS for stylesheets
#gem 'sass-rails'

# Use Uglifier as compressor for JavaScript assets
#gem 'uglifier'

# Use CoffeeScript for .js.coffee assets and views
#gem 'coffee-rails'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-ui-rails'

gem 'nokogiri'

gem 'mechanize'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end

gem 'devise'

#PW Schlüssel lokal abspeichern über env
gem 'figaro'

# Verschlüsselung des Feldes pw in Students
gem 'attr_encrypted'

#gem 'twitter-bootstrap-rails'

#gem 'protected_attributes'

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

感谢您的帮助!

最佳答案

您还可以做的是在本地为生产模式预编译您的 Assets

RAILS_ENV=production bundle exec rake assets:precompile:all

RAILS_ENV=production bundle exec rake assets:precompile

然后提交更改并将代码推送到服务器。

希望对您有所帮助!

关于jquery - Rails jquery 适用于本地主机,但不适用于 heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21518461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com