form-for

Change html form id generated by form_for rails 3.1

こ雲淡風輕ζ 提交于 2019-12-20 16:10:37
问题 I have this form_for: <%= form_for [post, Comment.new,], :remote => true do |f| %> <%= f.text_area :content, :cols =>10, :rows => 1%> <% end %> <%= f.submit :class => "input_comment" %> That generate the next code html: <form method="post" id="new_comment" data-remote="true" class="new_comment" action="/post/4efcda9e1d41c82486000077/comments" accept-charset="UTF-8"><div style="margin:0;padding:0;display:inline"><input type="hidden" value="✓" name="utf8"> <input type="hidden" value="ctVfDF

Ruby on Rails: Are “form_for(:product, …)” and “form_for(@product, …)” equivalent?

半腔热情 提交于 2019-12-20 14:36:49
问题 Is <%= form_for(:product, :url => {:action => 'update', :id => @product.id})) do |f| %> ... <% end %> and <%= form_for(@product, :url => {:action => 'update', :id => @product.id})) do |f| %> ... <% end %> exactly the same ? 回答1: The @product in the form_for helper ships with more features. The :product only affects the input field's id and name. For example you have a text filed in the form: <%= form_for :product, :url => {...} do |f| %> <%= f.text_field :price %> <% end %> The generated html

Submit button does not work unless I refresh the page form_for Rails

怎甘沉沦 提交于 2019-12-18 20:51:32
问题 I have an app that has a problem model and when I go to create a record the submit button does nothing. No errors given it just simply doesnt execute, unless I refresh the page and attempt add it again. The same happens when I go to update a record. Here is my controller class ProblemsController < ApplicationController include Concerns::Votes def index @problems = Problem.all end def show @problem = find_problem end def new @problem = Problem.new end def edit @problem = find_problem end def

Ruby on Rails : symbol as argument in form_for

狂风中的少年 提交于 2019-12-17 07:37:55
问题 I understand what is passed to the form_for method when doing something like : <% form_for(@user) do |f| %> ... <% end %> if @user is set in the controller. This is pretty obvious. But what happens when we pass :user , as I have seen in many examples ? <% form_for(:user) do |f| %> ... <% end %> When should I use the symbol version ? 回答1: Using the symbol will generate: <form action="/users" method="post"> Using the object @user set to new you get: <form action="/users/create" class="new_user"

rails 4 form_for with f.select isn't passing correct params, getting `param is missing` error

三世轮回 提交于 2019-12-14 03:21:56
问题 I have a shared partial using select fields and options_for_select that isn't passing the correct params to the controller. In the users_controller.rb, the view page user_home.html.erb: def user_home if user_signed_in? @user = current_user @cpe_event = CpeEvent.new end end In my cpe_events_controller.rb I have a #create action: def create @cpe_event = CpeEvent.new @user = current_user @cpe_event = current_user.cpe_events.build(cpe_event_params) ... The data is submitted by a form_for - a

UJS, AJAX, Rails 4, form_for collection_select to pass value into method and return value back to form

≡放荡痞女 提交于 2019-12-13 16:25:03
问题 I'm very new to Rails, and as such am having lots of of confusion when dealing with AJAX, UJS and Rails together. I've looked at railscast, several SO answers, tried #rubyonrails IRC channel on freenode. Alas, I'm still stuck. Anyway, here is my problem. SO I have two Models, Building and Property. Property belongs_to Building and Building has_many Properties. I've added the foreign key to Property as building_id. Now, in my building model, I have a Method: self.search(search) and given the

routing scope problem with form_for (partial)

狂风中的少年 提交于 2019-12-13 13:18:11
问题 Trying to route: scope :shortcut do resources :text_elems end Using basic scaffold with form partial *_form.html.erb* <%= form_for(@text_elem, :shortcut => @shortcut) do |f| %> ... Problem is : When I call the edit action, the form html shows as: <form ... action="/25/text_elems/25"> Note: The new action renders the form action correctly: <form ... action="/home/text_elems"> So it appears that my :shortcut param is getting trumped by the :id param when form_for processes it's block. Now I am

Class to form_for Ruby on Rails

允我心安 提交于 2019-12-13 07:47:08
问题 I don't get why this return me a error <%= form_for(@user), :html => {:class => 'form-connexion'} do |f| %> <%= render 'shared/error_messages' %> <%= f.label :name %> <%= f.text_field :name %> <%= f.label :email %> <%= f.text_field :email %> <%= f.label :password %> <%= f.password_field :password %> <%= f.label :password_confirmation, "Confirm Password" %> <%= f.password_field :password_confirmation %> <%= f.submit "Save changes", class: "btn btn-large btn-primary" %> <% end %> D:/xxxxxxx/app

Javascript only executing the first time when sending XHR requests with Remote true in form_for

女生的网名这么多〃 提交于 2019-12-13 05:44:36
问题 I have a form for filtering products, and want to change by AJAX the results on the partial for results: <%= form_for :pin, url: filter_path, method: :get, remote: true do |f| %> <%= f.radio_button :category, category %> <%= f.range_field :max_value , type: "range", value: "1000", min: "1", max: "1000" %> <%= f.submit "Buscar", class: "margin_top width100" %> <% end %> In the controller, I respond to JS with a partial: respond_to do |format| format.js { render "filter_products" } format.html

Rails: dynamically changing form content

半城伤御伤魂 提交于 2019-12-13 04:38:35
问题 I am building message app in rails where user can send message from templates. I have a database of templates, and the user can select templates as per category. In my message model, I want to render the template dynamically based on category selected. I looked for examples on google, but was not able to find a relevant solution. This is my message form: <%= form_for @message, :html => {:multipart => true} do |m| %> <%= m.select :biz_case, options_for_select(Message::Bcase), :prompt =>