form-for

Rails 4: f.select returns string not integer

橙三吉。 提交于 2020-01-04 04:37:11
问题 I have form for user registration. User has to select his country via select options. When i submit form i get error Country(#70309119520500) expected, got String(#8039220) Help me please how to convert string to integer so i can insert record in database. ruby -v: ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux] rails -v: Rails 4.1.8 This is my html.rb form <%= form_for :user, url: users_path do |f| %> <div class="field"> <%= f.label :countries %> <% options = options_from

Add class to bootstrap_form_for collection_select in Rails 5

不羁岁月 提交于 2020-01-02 08:43:27
问题 I use bootstrap_form_for to create forms and have a collection select, where I want to add a custom class. I tried this, but this does not work: <%= f.collection_select :location, Location.all, :id, :name, label: 'Location', :include_blank => ("Select..."), hide_label: true, :class => 'location' %> Any ideas? 回答1: Many Rails helpers take multiple hash arguments. And the definition of this collection_select method looks like this: collection_select(object, method, collection, value_method,

Add class to bootstrap_form_for collection_select in Rails 5

久未见 提交于 2020-01-02 08:42:32
问题 I use bootstrap_form_for to create forms and have a collection select, where I want to add a custom class. I tried this, but this does not work: <%= f.collection_select :location, Location.all, :id, :name, label: 'Location', :include_blank => ("Select..."), hide_label: true, :class => 'location' %> Any ideas? 回答1: Many Rails helpers take multiple hash arguments. And the definition of this collection_select method looks like this: collection_select(object, method, collection, value_method,

form_for wrong number of arguments (3 for 2) since upgrade to rails 3.1

萝らか妹 提交于 2020-01-02 01:03:33
问题 this form_for used to work before I ported my application to rails 3.1 <div class="form-box" style="padding-left:1em;"> <% action = @existing_mass.nil? ? "add_to_power_plant": "update_power_plant_substrate"; submit_button_label = @existing_mass.nil? ? 'Add': 'Update'; %> <%= form_for :substrate_mass, @substrate_mass, :remote => true, :url => { :action => action, :substrate_id => @substrate_mass.substrate } do |f| %> <div> <%= f.label :quantity_per_year, "Quantity" %> <%= f.text_field

How to upgrade the :update=>'div_id' option of remote_form_for from Rails 2 to Rails 3?

北战南征 提交于 2020-01-01 03:38:06
问题 I can't figure out how to upgrade this code from Rails 2 to Rails 3: <% remote_form_for(item, :update => 'div_id') do |f| %> ... I tried this: <%= form_for :item, :remote => true, :url => { :controller => "items", :action => "create" }, :update => 'div_id' do |f| %> ... It creates the new item but it fails in updating the content within <div id="div_id"></div> tags. It seems Rails 3 no longer supports the " :update " option for a remote form_for . Any suggestion? 回答1: You could use RJS, but

Rails: form_for namespaced resource

北城余情 提交于 2019-12-30 04:01:10
问题 I want to set up the CRUD for users, available just for administrators of my web application. So in routes.rb: namespace :admin do resources :user end which means this: admin_user_index GET /admin/user(.:format) admin/user#index POST /admin/user(.:format) admin/user#create new_admin_user GET /admin/user/new(.:format) admin/user#new edit_admin_user GET /admin/user/:id/edit(.:format) admin/user#edit admin_user GET /admin/user/:id(.:format) admin/user#show PUT /admin/user/:id(.:format) admin

STI and form_for problem

橙三吉。 提交于 2019-12-29 21:14:29
问题 I am using Single Table Inheritance for managing different types of projects. Models: class Project < ActiveRecord::Base end class SiteDesign < Project end class TechDesign < Project end Edit action from projects_controller: def edit @project = Project.find(params[:id]) end View edit.html.erb: <% form_for(@project, :url => {:controller => "projects",:action => "update"}) do |f| %> ... <%= submit_tag 'Update' %> <% end %> Update action of projects_controller: def update @project = Project.find

RoR differences between :url, :action, :method in form_for

眉间皱痕 提交于 2019-12-29 03:10:26
问题 There might be answers in documentation, but i don't seem to find good answers. So among the three :url, :action, :method, what are their differences when used in form_for in Rails? 回答1: Difference between :url , :action and :method :url If you want to submit your form for any particular controller, any particular action and want to pass some extra parameter (use action that define in controller that you pass on controller ) for example <%= form_for @post, :url => {:controller => "your

Configuring strong parameters for dynamic keys

前提是你 提交于 2019-12-25 07:49:47
问题 I'm attempting to provide a form that allows an admin to edit all values of a particular model Submission , almost as though it was a spreadsheet. Submission is comprised of one string field :domain . The problem is that I can't figure out how to deal with strong params within this context. I've found similar examples of dealing with dynamic keys like this one but I can't quite figure out how to apply them to my parameter structure. I think I'm just not clear enough on how tap works. Here's

Rails 4: Form_form controllerMethodName not working

谁说胖子不能爱 提交于 2019-12-25 06:47:16
问题 I am trying to set some params in a form_for in my view to be used by that View's Controller method called pay . Unfortunately I am getting the following error: NameError in WebApplications#pay undefined local variable or method `pay' for #<#<Class:0x000001082e1e00>:0x000001082e0fc8> Here is my View: <%= form_for pay do |f| %> <%= f.label :first_name %>: <%= f.text_field :first_name, params[:first_name] %><br /> <%= f.label :last_name %>: <%= f.text_field :last_name, params[:last_name] %><br