2013-08-21 52 views
0

我以前創建的視圖都工作正常。我爲訂閱生成了一個模型和控制器,並將相應的視圖鏈接到我的主頁。沒有錯誤拋出,但我的erb代碼沒有呈現給我的瀏覽器。我可以添加html(即包裹在div中的'hello world')。ERB代碼無法在視圖中顯示。開發環境

我試過以下。

  1. 剝離了周圍的html代碼,並試圖用erb包裝的rails helper方法。
  2. 刪除並重新生成兩種訂閱模式和訂閱控制器/視圖
  3. 經過我的routes.rb文件在兩個從SO無濟於事這些相關問題,看着訂閱相關的問題
  4. link1 link2

下面來看看我的代碼和輸出的WEBrick:

webrick output

# subscriptions/index.html.erb 

<% form_for(@subscription) do |f| %> 
<div class="container"> 
    <div class="row-fluid"> 
    <div class="span12"> 
     <div class="widget widget-table"> 
     <div class="widget-header"> 
      <h3> 
      <i class="icon-"></i>&nbsp;&nbsp;Pay with Credit Card 
      </h3> 
     </div> 
     <div class="widget-content"> 
      <table class="table table-striped table-bordered"> 
      <tbody> 
       <tr> 
       <td> 
        <% if @subscription.stripe_card_token.present? %> 
        Credit card has been provided. 
        <% else %> 
        <div class="control-group"> 
         <%= label_tag :card_number, "Credit Card Number" %> 
         <%= text_field_tag :card_number, nil, name: nil %> 
        </div> 
        </td> 
       </tr> 
       <tr> 
        <td> 
        <div class="control-group"> 
         <%= label_tag :card_code, "Security Code on Card (CVV)" %> 
         <%= text_field_tag :card_code, nil, name: nil %> 
        </div> 
        </td> 
       </tr> 
       <tr> 
        <td> 
        <div class="control-group"> 
         <%= label_tag :card_month, "Card Expiration" %> 
         <%= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month"} %> 
         <%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year"} %> 
        </div> 
        </td> 
        <% end %> 
       </tr> 
       <tr> 
        <td> 
        <div id="stripe_error"> 
        <noscript><!--Error here--></noscript> 
        </div> 
       </td> 
       </tr> 
      </tbody> 
      </table> 
     </div><!-- END CLASS widget-content --> 
     </div><!-- END CLASS widget widget-table --> 
    </div><!-- END CLASS span12 --> 
    </div><!-- END CLASS row-fluid --> 
</div><!-- END CLASS container --> 
<% end %> 

# routes.rb 

Whizcharts::Application.routes.draw do 
    resources :subscriptions, only: [:new, :create, :index] 
    # START devise routes 
    devise_for :admins, controllers: { registrations: "registrations" }# , path_names: { sign_in: "login", sign_out: "logout" } 

    mount Deviseadmin::Engine, at: "/deviseadmin" 

    devise_for :users, path_names: { sign_in: "login", sign_out: "logout" } 
    ## END devise routes 

    # START mailer 
    # match 'admins/show', to: "admins#show" 
    ## END mailer 

    # START static_pages routes 
    root to: "static_pages#home" 
    match "static_pages/about", to: "static_pages#about", as: :about 
    match "static_pages/pricing", to: "static_pages#pricing", as: :pricing 
    match "static_pages/contact", to: "static_pages#contact", as: :contact 
    ## END static_pages routes 

    # START deployments routes 
    match "deployments/deployment_print", to: "residents#deployment_print", as: :print 



# subscriptions_controller.rb 

# Note: Subscription.new is in the index method temporarily to demonstrate this issue 

class SubscriptionsController < ApplicationController 
    def index 
    @subscription = Subscription.new 
    @subscriptions = Subscription.all 
    end 

    def new 
    @subscription = Subscription.new 
    end 

    def show 
    @subscription = Subscription.find(params[:id]) 
    end 
end 

# subscription.rb 

class Subscription < ActiveRecord::Base 
    belongs_to :admin, dependent: :destroy 
    validates_presence_of :plan_id 

    attr_accessor :stripe_card_token 

    def save_with_payment 
    if valid? 
     customer = Stripe::Customer.create(plan: plan_id, card: stripe_card_token) 
     self.stripe_customer_token = customer.id 
     save! 
    end 
    rescue Stripe::InvalidRequestError => e 
    logger.error "Stripe error while creating customer: #{e.message}" 
    errors.add :base, "There was a problem with your credit card." 
    false 
    end 
end 


# admin.rb 

# Note: Included to demonstrate the association between the Admin and Subscription models 

class Admin < ActiveRecord::Base 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 
    attr_accessible :email, :password, :password_confirmation, :remember_me, :fac_name, :fac_address, :fac_city, :fac_state, :fac_zip, :lic_num, :owner_fname, :owner_lname, :fac_phone1,:fac_phone2, :fac_phone3, :fac_phone4, :fac_phone5, :fac_email1, :fac_email2, :fac_email3, :fac_email4, :fac_email5, :initials 

    has_many :residents 
    has_many :fund_record_form2s, through: :residents 
    has_many :deployments 
    has_many :subscriptions 

    def full_name 
    "#{owner_fname} #{owner_lname}" 
    end 
end 

我運行軌道3.2.14

如果我忘了什麼事,我將在您通知後立即安裝。

+1

您錯過了等號('=')符號。它應該是'<%= form_for(@subscription)do | f | %>' – Santhosh

+0

謝謝Neo!忽略了錯字。我讚賞這一點。 – sirramongabriel

+0

我已將它添加爲答案,您能接受嗎? – Santhosh

回答

1

您錯過了等於(=)的標誌。

它應該是<%= form_for(@subscription) do |f| %>

0

您在form_for helper之前缺少等號。

<%= form_for %> 

您需要等號,否則ERB標籤不會放在模板上。