2016-09-02 10 views
0

私はしばらく私の頭を壊していたので、あなたのうちの1人が私を助けてくれることを願っています。Rails/devise appがnew_user_registration_pathのために正常に動作しない

私は、クラウドプレビューで試した後、Herokuにアプリをデプロイしました。 問題は、有料のサブスクリプションのアカウントを作成するためにボタンを押すたびに、自分の資格情報を記入するページにリンクされていないことです。しかし、cloud9ではこれは正常に動作しているようです。

私はマウスを使ってさまざまなプラットフォームの同じボタンにカーソルを合わせることで、2つの違いがわかりました。 cloud9で

私が手:Herokuの上https://xxxxxxxx-xxxxx.xxxxxxx.xx/users/sign_up?plan=1

私が手に:私はHerokuの上のいずれかをクリックしたときにhttps://xxxxxxxx-xxxx-xxxxx.herokuapp.com/sign_up

だから、私は私のビルドを-で取得flashメッセージと言って:看板に会員プランを選択してくださいアップ!

もっと具体的に言えば、問題は私によると思いますが、変数が渡されるhome.html.erbのどこかにあると思います。 (下に追加されました)

私のHerokuではルーティングが正しく機能していないようですが、理由はわかりません。私は以下のファイルを追加しました。

誰かが私にこのことを助けてくれることを願っています! よろしくお願いいたします。

Gemfile

source 'https://rubygems.org' 


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '4.2.5' 
# Use sqlite3 as the database for Active Record 
gem 'sqlite3', group: [:development, :test] 
# Use postgresql as the database for production 
group :production do 
    gem 'pg' 
    gem 'rails_12factor' 
end 
# 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' 
# See https://github.com/rails/execjs#readme for more supported runtimes 
# gem 'therubyracer', platforms: :ruby 

# 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 

# Use ActiveModel has_secure_password 
# gem 'bcrypt', '~> 3.1.7' 

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

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

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 

### ADDED GEMS ### 

# Bootstrap Gem 
gem 'bootstrap-sass', '~> 3.3.6' 

# Devise Gem 
gem 'devise' 

# Font Awesome 
gem 'font-awesome-rails' 

# Use stripe for handling payments 
gem 'stripe' 

# Use figaro to hide secret keys 
gem 'figaro' 

ruby '2.3.0' 

routes.rbを

Rails.application.routes.draw do 
    devise_for :users, controllers: { registrations: 'users/registrations' } 
    resources :users do 
    resource :profile 
    end 
    resources :contacts 
    get '/about' => 'pages#about' 
    root 'pages#home' 
end 

pages_controller.rb

人の
class PagesController < ApplicationController 
    def home 
    @trial_plan = Plan.find_by id: '1' 
    @pro_plan = Plan.find_by id: '2' 
    end 

    def about 
    end 
end 

ユーザ/ registrations_controller.rb

class Users::RegistrationsController < Devise::RegistrationsController 
    before_filter :select_plan, only: :new 

    def create 
    super do |resource| 
     if params[:plan] 
     resource.plan_id = params[:plan] 
     if resource.plan_id == 2 
      resource.save_with_payment 
     else 
      resource.save 
     end 
     end 
    end 
    end 

    private 
    def select_plan 
     unless params[:plan] && (params[:plan] == '1' || params[:plan] == '2') 
     flash[:notice] = "Please select a membership plan to sign up." 
     redirect_to root_url 
     end 
    end 
end 

application.html.erb

<!DOCTYPE html> 
<html> 
<head> 
    <title>Ayris</title> 
    <%= stylesheet_link_tag 'application', media: 'all' %> 
    <%= javascript_include_tag "https://js.stripe.com/v2/", type: 'text/javascript' %> 
    <%= javascript_include_tag 'application' %> 
    <%= tag :meta, :name => "stripe-key", :content => STRIPE_PUBLIC_KEY %> 
    <%= csrf_meta_tags %> 
</head> 
<body> 
... 
     <%= link_to root_path, class: 'navbar-brand' do %> 
     <i class="fa fa-users"></i> 
     Ayris 
     <% end %> 
     ... 
     <% if user_signed_in? %> 
      ... 
     <% else %> 
      ... 
     <% if user_signed_in? %> 
      ... 
     <% end %> 
     <li><%= link_to "About", about_path %></li> 
     <li><%= link_to "Contact Us", new_contact_path %></li> 
     </ul> 
    </div><!-- /.navbar-collapse --> 
    </div> 
</nav> 

<div class="container"> 
    <% flash.each do |key, value| %> 
    <%= content_tag :div, value, class: "alert alert-#{key}" %> 
    <% end %> 

    <%= yield %> 
</div> 

</body> 
</html> 

home.html.erb

<% if user_signed_in? %> 
    ... 
     <% if current_user.profile %> 
      ... 
     <% else %> 
      ... 
     <% end %> 
    ... 
    <% else %> 
    <div class="col-md-6"> 
     <div class="well"> 
     <h2 class="text-center">Trial Membership</h2> 
     <h4>Sign up for free and get trial access for a period of 10 days.</h4> 
     <br/> 
     <%= link_to "Sign up for Trial", new_user_registration_path(plan: @trial_plan), class: 'btn btn-primary btn-lg btn-block' %> 
     </div> 
    </div> 
    <div class="col-md-6"> 
     <div class="well"> 
     <h2 class="text-center">Pro Membership</h2> 
     <h4>Sign up for the pro account for €75/month and get access to all functions.</h4> 
     <%= link_to "Sign up for Pro", new_user_registration_path(plan: @pro_plan), class: 'btn btn-success btn-lg btn-block' %> 
     </div> 
    </div> 
    <% end %> 
</div> 
+0

plan idが1または2になることを期待しています。コンソールにログインして 'Plan.pluck:id'を実行することで、両方のホストでこれが正しいことを確認する必要があります。私の勘違いは、それらの1つが異なるIDを持つことです。 – DiegoSalazar

+0

'2.3.0:001> Plan.pluck:ID (0.4ms)、 "計画" => FROM "計画" "ID" を選択し、[1、2]' これは、コンソールは、あなたがそう – Dacruz

+0

を返すものですプランIDが1または2のときにエラーを設定します – DiegoSalazar

答えて

0

問題を修正しました。あなたがデータベースについて言及したことは正しいものでした。問題は、何らかの理由でHerokuへのdb移行が失敗していることです。実行後:

Heroku run rails c
Plan.create(name: 'trial', price: 0)
Plan.create(name: 'pro', price: 75)

これらのコマンドを実行した後、両計画は私のHerokuのアプリのデータベースに注入しました。私は以下のコードを変更したaltough私のコードは、ヘッドアップのためのIDの

pages_controller.rb

class PagesController < ApplicationController 
    def home 
    if Plan.find_by name: 'trial' 
     @trial_plan = 1 
    end 
    if Plan.find_by name: 'pro' 
     @pro_plan = 2 
    end 
    end 
end 

感謝をハードコーディングについてコメントによると、今完全に正常に動作するようです。

関連する問題