我在我的控制器中有一個函數,我會渲染到另一個頁面,名爲thankyou。渲染工作正常,但在此之後,導軌再次將我重新導向謝謝,但這次它無法找到模板。我無法理解爲什麼rails會使我對同一個模板渲染兩次,並得到不同的結果。這是我的函數:Ruby缺失模板
def create
amount = params[:amount]
nonce = params[:payment_method_nonce]
if nonce.nil?
render :checkout
else
result = Braintree::Transaction.sale(
amount: amount,
payment_method_nonce: nonce
)
session[:user_id] = nil
render :thankyou
end
end
這是調用操作的形式創建:
<%= form_tag '/create', remote: true, id: "form", method: "post" do %>
<div class="col-md-12 text-left">
Choose you plan: <br>
<div>
<input class="collection_radio_buttons" id="plan_pro" name="amount" type="radio" value="0.99">
<label for="plan_pro">
<span class="fa-stack"><i class="fa fa-circle-o fa-stack-1x"></i><i class="fa fa-circle fa-stack-1x"></i></span>
<b>Pro</b><br>
</label>
</div>
<div>
<input class="collection_radio_buttons" id="plan_premium" name="amount" type="radio" value="1.98" checked="checked">
<label for="plan_premium">
<span class="fa-stack"><i class="fa fa-circle-o fa-stack-1x"></i><i class="fa fa-circle fa-stack-1x"></i></span>
<b>Premium</b><br>
</label>
</div>
<div>
<div id="paypal-container"> </div>
<input data-braintree-name="number" placeholder="Card number" class="string optional form-control input-box mailcode-form" maxlenght="16">
<input data-braintree-name="cvv" placeholder="CVV" class="string optional form-control input-box mailcode-form" width="3" maxlenght="3">
<input data-braintree-name="expiration_date" placeholder="Expiration date (e.g. 10/20)" class="string optional form-control input-box mailcode-form">
</div>
<div class="col-md-12 pull-right">
<input type="submit" class="signup-next" id="button_1" value="Pay 0,99 €">
<input type="submit" class="signup-next" id="button_2" value="Pay 1,98 €">
</div>
<% end %>
PS:從日誌似乎軌稱爲動作創造了兩次。這是我所提交表單後的實際日誌:
Started POST "/create" for 127.0.0.1 at 2015-06-30 15:47:06 +0200
Processing by HomeController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"S2LG9Bg4TrbXOoU4ewDBXHr0J1xtawrXy9hdSVjCBzA=", "amount"=>"1.98", "payment_method_nonce"=>""}
Rendered layouts/_social.html.erb (0.0ms)
Rendered home/_thankyou.html.erb (2.4ms)
Rendered home/thankyou.js (4.3ms)
Completed 200 OK in 16127ms (Views: 8.4ms)
[Braintree] [30/Jun/2015 13:47:38 UTC] POST /transactions 422
Started POST "/create" for 127.0.0.1 at 2015-06-30 15:47:22 +0200
Processing by HomeController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"S2LG9Bg4TrbXOoU4ewDBXHr0J1xtawrXy9hdSVjCBzA=", "amount"=>"1.98", "payment_method_nonce"=>"695c94a3-d219-44b6-af6f-cfec5dbb445f"}
Completed 500 Internal Server Error in 16376ms
ActionView::MissingTemplate (Missing template home/thankyou, application/thankyou with {:locale=>[:it, :en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
* "/home/marco/Scrivania/mailcoding_web/app/views"
* "/home/marco/.rvm/gems/ruby-2.2.1/gems/kaminari-0.16.3/app/views"
):
app/controllers/home_controller.rb:117:in `create'
Rendered /home/marco/.rvm/gems/ruby-2.2.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/missing_template.erb within rescues/layout (0.5ms)
我可以看到,有在片段缺少'end'文件替換。除此之外還有什麼可以讓':create'做更多的事情? –
不,這是我的錯誤 –
我編輯了我的答案。我想當你點擊:創建並渲染你的代碼選擇的模板時,你就會顯示:創建,也許?在if後面試試'return'? –