form-for

simple_form and hstore basic functionality

筅森魡賤 提交于 2019-12-06 13:32:00
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 hstore hash and it saves properly but on edit the values don't populate without using the input_html

ActionController::ParameterMissing param is missing or the value is empty

不问归期 提交于 2019-12-06 13:08:32
问题 I can't solve this problem. When I try to use "Chatroom#new" method, I I got this error, ActionController::ParameterMissing param is missing or the value is empty . below codes are the ChatroomController. class ChatroomsController < ApplicationController before_action :find_room_owner,only:[:index] before_action :objects_for_index,only:[:index] def index #/users/:user_id/cart/items/chatroom sign_in @user if signed_in? if @seller && @buyer flash[:success] = "U are owners of the chatroom"

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

瘦欲@ 提交于 2019-12-06 12:04:15
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 using I18n. How can I get the submit button to use "Create" when there's an existing record?

How do you use number_to_phone in Rails 3?

流过昼夜 提交于 2019-12-06 10:03:13
问题 I am storing phone number in database as "1234567890". How do can you use number_to_phone to display the number nicely in a form as "(123) 456-7890"? I tried the following but it showed just the numbers. <%= f.text_field number_to_phone(:phone_number) %> Thanks. 回答1: you can create a simple helper like this in your application helper def format_phone(phone, mobile=false) return phone if format.blank? groupings = format.scan(/d+/).map { |g| g.length } groupings = [3, 3, 4] unless groupings

Creating a simple drop-down menu in Rails

和自甴很熟 提交于 2019-12-05 09:14:09
问题 This really seems simple enough yet for some reason I'm missing something critical. I have a view: <% form_for :foo, @foo, :url => {:action => 'bar'} do |f|%> <%= f.collection_select :range, FooModel::MONTHS%> <%= submit_tag "Submit", :disable_with => "Submitting..." %> <% end %> I have a model: class FooModel < ActiveRecord::Base MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep'] end And I have a controller: def new @foo = FooModel.new end def index respond_to do

Capitalize f.text_field

限于喜欢 提交于 2019-12-05 05:07:24
I have a form_for and I want that any value inside x.textField appear with the first letter in Upcase (I'm talking about the edit where the textfield are prefilled by the db values). You can capitalize it like this: <%= form_for ... do |f| %> <%= f.text_field :name, :value => f.object.name.capitalize %> You can do this with CSS... = f.text_field :some_attribute, style: 'text-transform: capitalize;' Pan Thomakos's solution will work, but if you don't want to have to add :value => f.object.name.capitalize to every text field on the form, you could look into writing your own FormBuilder. Put this

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

佐手、 提交于 2019-12-05 03:22:33
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 don't seem to get any of the hidden field parameters sending to the controller. Started POST "/groups/1

ActionController::ParameterMissing param is missing or the value is empty

安稳与你 提交于 2019-12-04 19:52:54
I can't solve this problem. When I try to use "Chatroom#new" method, I I got this error, ActionController::ParameterMissing param is missing or the value is empty . below codes are the ChatroomController. class ChatroomsController < ApplicationController before_action :find_room_owner,only:[:index] before_action :objects_for_index,only:[:index] def index #/users/:user_id/cart/items/chatroom sign_in @user if signed_in? if @seller && @buyer flash[:success] = "U are owners of the chatroom" @messages = Message.all #Messageのmodelを作成 else flash[:error] = "U cant enter the chatroom." redirect_to user

Rails 3: using non-Active Record objects with form_for

本秂侑毒 提交于 2019-12-04 16:19:10
问题 Is there any documentation, or advice? 回答1: You can use Active Model Take a look here. Look at the source code at Github. 回答2: Using ActiveAttr is the more modern way of doing this. Gem: https://github.com/cgriego/active_attr Railscast: http://railscasts.com/episodes/326-activeattr 来源: https://stackoverflow.com/questions/4241779/rails-3-using-non-active-record-objects-with-form-for

How do you use number_to_phone in Rails 3?

孤者浪人 提交于 2019-12-04 15:18:55
I am storing phone number in database as "1234567890". How do can you use number_to_phone to display the number nicely in a form as "(123) 456-7890"? I tried the following but it showed just the numbers. <%= f.text_field number_to_phone(:phone_number) %> Thanks. you can create a simple helper like this in your application helper def format_phone(phone, mobile=false) return phone if format.blank? groupings = format.scan(/d+/).map { |g| g.length } groupings = [3, 3, 4] unless groupings.length == 3 ActionController::Base.helpers.number_to_phone( phone, :area_code => format.index('(') ? true :