我是rails的新手,我已经创建了一个非常简单的示例,但是我的for不会在下面提交的是组件:
This is my controller:
class ProfilesController < ApplicationController
def new
logger.info "from new"
@profile = Profile.new
logger.info "after new"
end
def show
end
def list
@profile = Profile.find(:all)
end
def create
logger.info "from create"
@profile = Profile.new(user_basic_params)
if @profile.save
redirect_to '/show'
else
render 'show'
logger.info "Save failed"
flash[:notice] = "Didn't work"
end
end
def index
end
def user_basic_params
logger.info "from user_basic_params"
params.require(:profile).permit(:email, :password, :file, :active, :sex, choises: [])
end
end
这是我的观点:
<div class="container center-block">
<div class="row">
<form class="form-horizontal">
<div class="form-group">
<h3> Create new profile </h3>
</div>
<%= simple_form_for (@profile) do |f| %>
<div class="form-group">
<%= f.input :milk_animal, as: :radio_buttons, collection: ['Cow','Any'], placeholder: 'Enter Milk Animal' %>
</div>
<div class="form-group">
<%= f.input :milk_type, as:
:radio_buttons, collection: ['Toned','Any'], placeholder: 'Milk Type' %>
</div>
<div class="form-group">
<%= f.input :brand, placeholder: 'Brand' %>
</div>
<div class="form-group">
<%= f.label :Time_of_Delivery %>
<%= f.time_select :time_of_delivery, placeholder: 'Time of Delivery' %>
</div>
<div class="form-group">
<%= f.label :Start_Date %>
<%= f.date_select :start_date, placeholder: 'Start Date' %>
</div>
<div class="form-group">
<%= f.input :delivery_days, as: :check_boxes,
collection: [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Satusday',
'All'],
wrapper: :vertical_radio_and_checkboxes %>
</div>
<div class="form-group">
<%= f.input :name, placeholder: 'Name' %>
</div>
<div class="form-group">
<%= f.input :address, as: :text, placeholder: 'Address' %>
</div>
<div class="form-group">
<%= f.input :pincode, placeholder: 'Pincode' %>
</div>
<div class="form-group">
<%= f.input :contact_no, placeholder: 'Contact No' %>
</div>
<%= f.button :submit %>
<% end %>
</form>
</div>
</div>
我的模型名称是配置文件,控制器名称是配置文件 在我的route.rb文件中写了:resources:profiles
当我查找在浏览器中生成的html源代码时,表单以这种方式呈现:
<form novalidate="novalidate" class="simple_form new_profile" id="new_profile" action="/profiles/create" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="authenticity_token" value="+qcqmHIbaskK/QIu5vy66UY9xHlzr8TkpwAUFzkM+Q5SwaU6Zy6qQLhfZYgsGuLS+XU8ghX+C+aHJPrO2u6BWg==" />
通过查看将要创建方法的操作,但似乎没有。
最后我的控制台输出是:
Started GET "/profiles/new" for 127.0.0.1 at 2015-05-31 00:49:48 +0530
Processing by ProfilesController#new as HTML
from new
after new
Rendered profiles/new.html.erb within layouts/application (142.4ms)
Completed 200 OK in 178ms (Views: 166.7ms | ActiveRecord: 0.7ms)
Started GET "/profiles/new?utf8=%E2%9C
Processing by ProfilesController#new as HTML
Parameters: "brand"=>"Amul", "commit"=>"Create Profile"}
from new
after new
Rendered profiles/new.html.erb within layouts/application (158.2ms)
I have deleted few parameter in output