form-helpers

Rails nested forms with pre-defined fields as checkboxes

大城市里の小女人 提交于 2019-12-06 12:27:29
问题 I'm making a hotel app that includes Room and RoomAttribute models. The two models have a many_to_many relationship between each other through a join table. The attributes for each model are as follows: Room – room_number , room_type (e.g. "deluxe" or "suite"), and price . RoomAttributes – name (e.g. "Wireless Internet", "Cable TV", "Bath Tub"). The user will first create a set of room attributes, so that these can be selected as checkboxes every time a new room is created. For example, some

How to create a delete form with RESTful routes in Rails.

血红的双手。 提交于 2019-12-06 11:10:24
I am trying to create a form that serves as confirmation for the destroy method on a controller. In my routes I have: resources :leagues do get 'delete', :on => :member end In my delete.html.erb, I have the following for: <% form_for current_league, :html => {:method => :delete} do |form| %> <%= form.submit 'Yes' %> <%= form.submit 'No', :name => 'cancel' %> <% end %> current_league is a helper function defined by: def current_league @current_league ||= League.find_by_id(params[:id]) end So the problem is that the form that is generated only edits the league model, as seen by the form method=

Custom HTML attribute requires a custom helper?

走远了吗. 提交于 2019-12-03 22:44:11
I'm trying to create a form with some custom data attributes on the inputs: <input type="text" data-family="Dinosaurs"> This seemed like a nice clean way to have easy front-end access (haha!) with jquery: $("[data-family='Dinosaurs']").doSomething() The problem is I can't get Rails (3.0.3) to render the attribute. <%= f.text_field :question, :id=>"poll_question", :class=>"BigInput", :style=>"width:98%;", :attributes=>"data-submit_clear='1'" %> I've tried many permutations to no avail and can't find an example of how to do this. Do I need to modify the text_field helper to support any custom

Why does the check_box form helper generate two checkboxes, one hidden?

血红的双手。 提交于 2019-12-03 20:09:42
问题 this code: =form_fo :store_products do |f| = f.check_box :track_inventory creates this html: <input name="product_group[products_attributes][0][store_products_attributes}[1342647745501][track_inventory]" type="hidden" value="0"> <input id="product_group_products_attributes_0_store_products_attributes_1342647745501_track_inventory" name="product_group[products_attributes][0][store_products_attributes][1342647745501][track_inventory]" type="checkbox" value="1"> What is the reason for the first

Use custom id for check_box_tag in Rails

三世轮回 提交于 2019-12-03 11:31:04
问题 How do you set a custom id when using a check_box_tag helper in rails? I have a loop which creates a bunch of checkboxes based on a collection: - subject.syllabus_references.each do |sr| = check_box_tag 'question[syllabus_reference]', sr.id, :id => sr.id = label_tag sr.id, sr.name I would like to set a custom id so that my Label for the checkbox works correctly but I can't seem to figure out how (:id => sr.id does not work...). The problem might also be with the way I've defined the label, so

include bootstrap role attribute in rails form helper

旧巷老猫 提交于 2019-12-03 07:00:55
Twitter Bootstrap has this role attribute for forms: <form role="form"> How can I include the role attribute in Rails form helpers? I tried this, but it doesn't work: <%= form_for @user, class: "form-horizontal", role: "form" do |f| %> You need to specify it as an html option: <%= form_for @user, html: {class: "form-horizontal", role: "form"} do |f| %> form_for and form_tag have to be used differently: form_for: <%= form_for @user, html: { class: "form-horizontal", role: "form" } do |f| %> form_tag: <%= form_tag some_path, class: "form-horizontal", role: "form" do |f| %> 来源: https:/

Use custom id for check_box_tag in Rails

南笙酒味 提交于 2019-12-03 02:56:27
How do you set a custom id when using a check_box_tag helper in rails? I have a loop which creates a bunch of checkboxes based on a collection: - subject.syllabus_references.each do |sr| = check_box_tag 'question[syllabus_reference]', sr.id, :id => sr.id = label_tag sr.id, sr.name I would like to set a custom id so that my Label for the checkbox works correctly but I can't seem to figure out how (:id => sr.id does not work...). The problem might also be with the way I've defined the label, so if I can get that to reference the correct check box without setting a custom id then that would be

CakePHP 2.0 Select form Mulitple selected

被刻印的时光 ゝ 提交于 2019-12-01 19:04:54
Ok, so I have have this dropdown menu where you can select multiple values. Now lets say I want to edit my info and make a dropdown menu with multiple selected values. Trying to figure out how it goes, but no results. Lets say I have: $selected = array(3, 4); $options = array(1,2,3,4); echo $this->Form->select('Attendees', $options,array('multiple' => true, 'selected' => $selected)); I've used this code, but nothing is selected. Ok found a way, appearantly it needs to be like this: $selected = array(2, 3); $options = array(1, 2, 3, 4); echo $this->Form->input('Attendees', array('multiple' =>

Input wrapper div class in CakePHP 3.0.0

荒凉一梦 提交于 2019-12-01 17:13:29
How can I change input wrapper div class in CakePHP 3.0.0.? My code is: <?= $this->Form->input('mobile',['div'=>['class'=>'col-md-4'],'class'=>'form-control','label'=>false]) ?> and it returns: <div class="input text"> <input type="text" name="mobile" div="col-md-4" class="form-control" id="mobile"> </div> I want output like: <div class="col-md-4"> <input type="text" name="mobile" class="form-control" id="mobile"> </div> For CakePHP 3.0 versions ... ... there is no way to just pass on attributes to a template. You'd have to redefine the appropriate form helper templates. You can either change

Input wrapper div class in CakePHP 3.0.0

橙三吉。 提交于 2019-12-01 15:57:46
问题 How can I change input wrapper div class in CakePHP 3.0.0.? My code is: <?= $this->Form->input('mobile',['div'=>['class'=>'col-md-4'],'class'=>'form-control','label'=>false]) ?> and it returns: <div class="input text"> <input type="text" name="mobile" div="col-md-4" class="form-control" id="mobile"> </div> I want output like: <div class="col-md-4"> <input type="text" name="mobile" class="form-control" id="mobile"> </div> 回答1: For CakePHP 3.0 versions ... ... there is no way to just pass on