【发布时间】:2016-10-19 16:12:50
【问题描述】:
我的应用已通过身份验证并在其主页上正确显示来自 API 调用的信息,但我无法让它在使用代理的页面上显示来自 API 调用的信息。代理设置正确,因为如果其页面上只有 HTML(没有 Shopify API 调用),它将显示 HTML。
routes.rb
Rails.application.routes.draw do
root :to => 'home#index'
mount ShopifyApp::Engine, at: '/'
get "/products" => "products#index", :as => :products
end
products_controller.rb
class ProductsController < ShopifyApp::AuthenticatedController
around_filter :shopify_session
def index
@productArray = ShopifyAPI::Product.find(:all, :params => {:limit => 10})
end
end
index.html.erb
<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>
我的 Shopify 代理
Path: a/products
Proxy url: https://appname.herokuapp.com/products
现在是奇怪的部分
当我转到https://devstorename.myshopify.com/a/products 时,它只是重定向到https://devstorename.myshopify.com/password。没有通知或任何东西。如果我从控制器中删除了 index 函数并将 html 文件更改为仅包含类似 -
<h1>Test</h1>
然后它会在屏幕上正确显示“测试”而没有重定向。我由此得出的结论是,我可能存在某种身份验证问题,我无权在此页面上进行调用。
然而,所有这些代码都适用于 home_controller.rb 控制器及其 index.html.erb,并且正确的信息会显示在根路由中。
我显然对此很陌生。
编辑
使用应用代理 gem,
products_controller.rb
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
【问题讨论】:
标签: ruby-on-rails model-view-controller shopify