我的应用已经过身份验证,并在其主页上正确显示来自API调用的信息,但我无法使用代理在页面上显示来自API调用的信息。代理设置正确,因为如果页面上只有HTML,它将显示HTML(没有Shopify API调用)。
Rails.application.routes.draw do
root :to => 'home#index'
mount ShopifyApp::Engine, at: '/'
get "/products" => "products#index", :as => :products
end
class ProductsController < ShopifyApp::AuthenticatedController
around_filter :shopify_session
def index
@productArray = ShopifyAPI::Product.find(:all, :params => {:limit => 10})
end
end
<h2>Products</h2>
<ul>
<% @productArray.each do |product| %>
<li><%= link_to product.title, "https://#{@shop_session.url}/admin/products/#{product.id}", target: "_top" %></li>
<li><%= product.id %></li>
<% end %>
</ul>
Path: a/products
Proxy url: https://appname.herokuapp.com/products
当我转到https://devstorename.myshopify.com/a/products时,它只会重定向到https://devstorename.myshopify.com/password。没有通知或任何东西。如果我从控制器中删除索引函数并将html文件更改为仅包含类似 -
的内容<h1>Test</h1>
然后它将在屏幕上正确显示“Test”而没有重定向。我的结论是,我可能遇到某种身份验证问题,我无法在此页面上进行调用。
然而,所有这些代码都适用于home_controller.rb控制器及其index.html.erb,并且正确的信息将显示在根路径上。
我显然对此非常陌生。
使用app proxy gem,
class ProductsController < ShopifyApp::AppProxyController
def index
@productArray = ShopifyAPI::Product.find(:all, :params => {:limit => 10})
end
end
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
gem 'shopify_app', :github => 'mikeyhew/shopify_app', :branch => 'app-proxy'
gem 'json'
# Use sqlite3 as the database for Active Record
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# 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', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
答案 0 :(得分:0)
据我了解,ShopifyApp::AuthenticatedController
并不打算在app代理后面使用:你只能在嵌入式应用程序中继承它。
至于重定向到/密码,听起来你的店面受密码保护。我建议您在继续使用应用代理之前将其关闭,因为这会让您感到困惑。