我之前创建的视图都运行良好。我为订阅生成了一个模型和控制器,并将相应的视图链接到我的主页。没有错误,但我的erb代码没有呈现给我的浏览器。我可以添加html(即'hello world'包含在div中)。
我尝试了以下内容。
以下是webrick的代码和输出:
# 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> 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
我正在运行rails 3.2.14
如果我遗忘了某些内容,我会在收到通知后立即提出。
答案 0 :(得分:1)
您错过了等号(=
)。
应为<%= form_for(@subscription) do |f| %>
答案 1 :(得分:0)
您在form_for帮助程序之前缺少等号。
<%= form_for %>
您需要等号,否则ERB标签不会放在模板上。