我有一個在mypage.html.erb
複選框的列表。當我選中一個方框並單擊「提交」按鈕時,我想要在下一頁(bookfinal.html.erb
)中選中要打印的內容的值。出於某種原因,檢查的值不打印?在控制檯中,選中的值顯示爲'1',所以我不確定丟失了什麼。如您所見,我添加了@checked = "Test"
以查看該值是否會打印,但它仍然沒有?SubmitForm檢查值不張貼到頁面
mypage.html.erb
<div class="infoheaders">1. Question
<%= simple_form_for @category, :url => url_for(:action => 'bookfinal', :controller => 'users'), :method => 'post' do |f| %>
<%= f.collection_select(:title, Category.all, :title, :title) %>
<div class="grey-text-subheader">Device: (optional)</div>
<%= f.check_box :Apple %> <%= f.label "Apple" %>
<%= f.check_box :iPhone %> <%= f.label "iPhone" %>
<%= f.check_box :iPad %> <%= f.label "iPad" %>
<%= f.check_box :Mac %> <%= f.label "Mac" %>
<%= f.check_box :Android %> <%= f.label "Android" %><br><br>
<%= f.check_box :Samsung %> <%= f.label "Samsung" %>
<%= f.check_box :Microsoft %> <%= f.label "Microsoft" %>
<%= f.check_box :Windows %> <%= f.label "Windows" %>
<%= f.check_box :Google %> <%= f.label "Google" %>
<%= f.button :submit, 'Submit' %>
<% end %>
</div>
users_controller.rb
def bookfinal
if params[:category][:ipad].present?
@checked = params[:category][:ipad]
end
if params[:category][:android].present?
@checked = params[:category][:android]
end
if params[:category][:samsung].present?
@checked = params[:category][:samsung]
end
@checked = "Test"
end
bookfinal.html.erb
<div>
The checked value is <%= @checked %>
</div>
的routes.rb
Rails.application.routes.draw do
get 'categories/new'
get 'sessions/new'
post 'categories' => 'categories#create'
get 'users/edit'
get 'users/new'
get 'users/index'
get 'users/mypage'
post "users/bookfinal" => 'users#bookfinal'
resources :users
resources :categories
控制檯
Started POST "https://stackoverflow.com/users/bookfinal" for 96.49.105.234 at 2016-02-19 21:18:21 +0000
Processing by UsersController#bookfinal as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"zaPn5YuBFYr9VwPDSNMeA7tfm74sjM8HZneG+PCX9HEPEH/mb2qgA4xDacI9YDgcjDlFgKCQFFgWnUs5AZB0MA==", "category"=>{"title"=>"Digital Marketing", "Apple"=>"0", "iPhone"=>"0", "iPad"=>"1", "Mac"=>"0", "Android"=>"0", "Samsung"=>"0", "Microsoft"=>"0", "Windows"=>"0", "Google"=>"0"}, "commit"=>"Submit"}
Rendered users/bookfinal.html.erb within layouts/application (0.6ms)
Completed 200 OK in 115ms (Views: 113.8ms | ActiveRecord: 0.0ms)
寫'的routes.rb '請和服務器日誌 – Ilya
@Ilya看到路由和控制檯發佈。 – Brittany
好像沒問題..試着保存你的編輯和重啓服務器 – Ilya