form-for

How to prevent polluting a rails object when using form_for and .new?

我们两清 提交于 2019-12-25 04:59:09
问题 I have a model: class Activity < ActiveRecord::Base has_many :activity_states end I want to render options for new activity states and render existing activity states. However when I use this form_for: <%= form_for activity.activity_states.new, :remote => true do |f| %> <%= f.hidden_field :state_type, :value => activity_state_type %> <%= f.hidden_field :activity_id %> <%= f.submit submit_label, :disable_with => 'sending...' %> <% end %> for creating new temporary activity_state models to use

Rails 3 form_for ajax call

∥☆過路亽.° 提交于 2019-12-24 00:52:20
问题 I have method in my controller: def work_here @company = Company.find(params[:id]) current_user.work_apply(current_user, @company) redirect_to company_path end On my view: <%= render 'companies/work_form' if signed_in? %> _work_form.html.erb: <%= form_for company, :remote => true, :url => { :controller => "companies", :action => "work_here" } do |f| %> <%= f.hidden_field :id, :value => company.id %> <%= f.submit "I working here" %> <% end %> And I have a work_here.js.erb file: $("#work_at

nested form with polymorphic models

夙愿已清 提交于 2019-12-23 12:39:08
问题 I'm making an app with the following attributes, and I'm working on a creating a single form to be able to save a goal, a goal's tasks, a goal's milestones, and a milestone's tasks. #app/models/goal.rb has_many :tasks, :as => :achievement has_many :milestones accepts_nested_attributes_for :tasks accepts_nested_attributes_for :milestones #app/models/milestone.rb belongs_to :goal has_many :tasks, :as => :achievement #app/models/task.rb belongs_to :achievement, :polymorphic => true Whenever I

rails virtual attributes won't read from form_for submission

爷,独闯天下 提交于 2019-12-23 03:32:18
问题 I am trying to implement a rails tagging model as outlined in Ryan Bate's railscast #167. http://railscasts.com/episodes/167-more-on-virtual-attributes This is a great system to use. However, I cannot get the form to submit the tag_names to the controller. The definition for tag_names is : def tag_names @tag_names || tags.map(&:name).join(' ') end Unfortunately, @tag_names never gets assigned on form submission in my case. I cannot figure out why. SO it always defaults to tags.map(&:name)

Getting submit button label to be “Create model” instead of “Update model” inside form_for in rails

大城市里の小女人 提交于 2019-12-22 18:28:19
问题 I am rendering a form using form_for with an existing model. I would like to submit that model and get the next action to be performed to be the 'create' action. The docs have this example: <%= form_for @post do |f| %> <%= f.submit %> <% end %> And say "In the example above, if @post is a new record, it will use “Create Post” as submit button label, otherwise, it uses “Update Post”." I am relatively new to rails and am not sure what to make of the following stuff in the docs about customizing

simple_form and hstore basic functionality

两盒软妹~` 提交于 2019-12-22 18:15:33
问题 I can get hstore to work with simple_form but all but the most basic functionality (saving) just doesn't work. Validation messages don't show up on the individual fields... all hstore fields oddly show as required, even the values themselves don't populate correctly unless set manually. I have to do something like this: <%= f.simple_fields_for :phones do |phone| %> <%= phone.input :agent, :input_html => { :value => @artist.phones['agent'] } %> <% end %> I have to use simple_fields_for for the

Rails: Hidden field in form_for is not sending parameters to controller

好久不见. 提交于 2019-12-22 04:16:26
问题 I have a form_for I'm making in my view helper that is going to let one user promote another user from a group. def promote_button_for(group, user) membership = group.get_membership( user ) form_for membership, :url => group_membership_path( group, membership ) do |f| f.hidden_field :group_creator hidden_field_tag 'test', '1' f.submit( "Promote", :onclick => "return confirm(\"Are you sure you want to promote #{user.email} to an officer?\")" ) end end When I submit the form via the button, I

Ruby form using ajax with remote: true gives ActionController::InvalidAuthenticityToken error. Classic submission does not

不想你离开。 提交于 2019-12-21 11:25:17
问题 I am writing a chat page for a RoR site. I have it all worked out in HTML and I am trying to implement it with ajax. There is a form for submission of messages. the form tag reads <%= form_for(@chat, remote: true, :authenticity_token => true) do |f| %> My entire view: <!DOCTYPE html> <html> <head> <title>Battleriskopoloy - Communications</title> </head> <body> <br> <div id="heading_1" align="center"> <br><span id="title"><strong>[ . . . Communications . . . ]</strong></span> </div><br> <div

Spree Dropdown boxes for variant option values

核能气质少年 提交于 2019-12-21 05:06:49
问题 I'm learning Spree 3.0 and I have a setup a test shop that sells shorts. Shorts has multiple option types: Size, Color, Length I wanted to change the way it displays the variant options on the frontend from a radio checkbox to a drop down box. Currently, Spree displays the option types as radio buttons: I want to change this to use drop down menus for each option type, like this: I've tried the following: <%= select_tag "variant_id", options_for_select(@product.variants_and_option_values

Custom name for params hash from Rails form_for

心已入冬 提交于 2019-12-21 03:10:28
问题 Ordinarily, using form_for(@foo) means that on the back end of the form's action, you'll have the form data in params[:foo] , but in my case I'd like to have a custom namespace applied to these params, i.e. params[:bar] , not params[:foo] . I'm not talking about making the namespace longer by supplying the :namespace argument to the form_for method. To the contrary, my current name is overlong, and I want to shorten it. More importantly, I'm actually swapping a new model in place of an