similar to: Using rails form helpers for non model objects

Displaying 20 results from an estimated 40000 matches similar to: "Using rails form helpers for non model objects"

2010 Jul 19
1
instance_exec routes -> form helpers
The new router in Rails 3 is clean and concise and marks the acceptance of instance_exec as a method for writing a gorgeous DSL. I''m wondering should something similar be applied to the default form helpers? Moving from this: <%= form_for(@post) do |f| %> <%= f.text_field :title %> <% end %> to this: <%= form_for(@post) do %> <%= text_field :title %>
2006 Apr 24
4
Does Rails need more useful form helpers?
I have been using rails professionally for only a month and a half now, but I am continually running into problems with form helpers and accessing multiple objects on a single page. To whit: 1. While text_field and text_area and such all support the :index option, the select helper does not. 2. When appending the text ''[]'' to a helper''s object name, the id is
2006 Nov 04
0
Using Field Helpers to Edit a Related Model Object
Hello folks, Here''s a question about creating an edit screen for a model and a related model. On page 355 of the AWDWR book (printed page 464 of the 2nd edition pdf), there''s a little table showing how form parameters map to the params object. One of them is: user[address][city]=Wien ... maps to params as ... { :user => { :address => { :city =>
2011 May 20
3
How to handle non model data in form?
Hey, I got a form which looks like this: - form_for(@article, :html => {:multipart => true}, :url => articles_path) do |f| = errors_for(@article) .field = f.label :text %br = f.text_field :text .field = f.label :author_id %br = f.text_field :author_id .actions = f.submit But since I don''t want anyone to type in an author id I changed it
2006 Jul 16
1
form helpers with non-ActiveRecord objects
I have an ActiveRecord model (called Festival) that contains an array of "FestDate" objects serialized into a sql text column of the Festival object. (like the Agile book first edition describes on p. 205) The FestDate objects themselvs are not ActiveRecord objects. (of course, otherwise they would be in their own table...) When working with a Festival, I would like to use various
2009 Feb 05
1
[rspec] [rails] Specing a form builder
I''m trying to set up and run a new form builder under rails, which lives under the helpers directory, but isn''t really a helper. (Not a module, so doesn''t mix in well) Short of dropping down into a view spec, how do I set up to actually spec the form builder? describe RandomFormBuilder do attr_reader :builder before do @object = mock_model(Foo) @builder =
2006 Jan 13
5
Form field naming semantics question
Hi, I have a question today regarding how the various form elements in _form.rhtml are named. I understand that for a database table "persons" with a column headed by "name", then in _form.rhtml it will probably be like: <p><label for="person_name">Name><br/> <%= text_field ''person'', ''name''
2006 May 19
2
1 Form for Model containing another Model??
Hi, I can have a Person model with a "has_one :address_email" association, then do the following in my controller: @person = Person.new @person.address_email = AddressEmail.new But, when I have 1 form for "Person" in my view I can''t bind fields in the @person.address_email object with text_field or text_field_tag helpers without getting a "undefined local
2006 Jun 12
3
Multiple Form Fields with Same Model?
Hello, I''m trying to create a form that will allow a user to submit a list of phone numbers, but the list is dynamically created. Thus allowing my form to submit an unknown number of phone numbers. Here is some of the code I have been trying: <%= collection_select( "phone[]", "phone_type_id", PhoneType.find(:all, :order => "position"),
2006 Jan 11
0
Easy Question, I Think
I am just getting started with Rails, don''t know any Ruby, and don''t quite even get object oriented programming yet. I have tweaked my schema to The Rails Way and have generated a bit of scaffolding. I am trying to create a new Part, which references a PartName and a PartNumber. I can create a PartNumber on the fly, but the PartName has to exist. I have an inelegant solution
2006 Apr 08
2
ActionView::Helpers::FormHelper instance methods should take an object reference rather than an object_name.
Hi ActionView::Helpers::FormHelper methods (e.g. #text_field, #check_box...) take object_name as an argument. From this argument they infer a name that is supposed to contains the reference to the relevant object. I can''t see why the FormHelper methods were designed that way. Compared to simply passing them a reference, the current way seems too complicated and an invitation to problems
2006 Jun 01
0
overriding form helpers
Hi there, I''ve been trying to override the text_field helper with a version in my application helper. Whenever I try and call it from a partial I get the error: "uninitialized constant InstanceTag" I can override the text_field_tag no problem. But there''s lots of stuff I don''t understand in text_field. All I really want to do is set some common options for
2006 Jan 12
0
Easy Question, I Think [re-post, sorry if dupe]
I am just getting started with Rails, don''t know any Ruby, and don''t quite even get object oriented programming yet. I have tweaked my schema to The Rails Way and have generated a bit of scaffolding. I am trying to create a new Part, which references a PartName and a PartNumber. I can create a PartNumber on the fly, but the PartName has to exist. I have an inelegant solution
2007 Dec 09
0
Writing Specifications for Custom Form Builders (and Helpers)
Hello all, Long time reader, first time poster! I am a relative newcomer (no idea what on earth I am doing) to Ruby, Rails and Rspec and have a feeling I am probably trying to run before I know how to walk. I had imagined a cool way of outputting a div around some form stuff which would have a class on it if the related field had errors, something a bit like: <%
2006 Jan 21
5
How do you deal with non-model property form values
I have a User ActiveRecord model that has email and password properties. I want to build a login for that has a "remember me" option. My view looks like this: <% @page_title = "Login" -%> <%= error_messages_for ''user'' %> <%= form_tag %> <table> <tr> <td align="right" width="1%"
2006 Mar 01
3
Form helpers and overloaded methods - help!
Can someone explain why form helpers appear to bypass any model methods I override for fields that are bound to database fields? It would be great if someone could tell me how to force the form field, etc to call the method instead of looking at the database / attributes collection. Let''s say I have a column called ''price'' in my database table "books"
2006 Jul 11
4
add method parameter for form helper
Hello, Most of the form helpers are build using Object / Method without the possibility of using a method parameter (as I know ...) text_field(object_name, method, options = {}) how do you solve this problem ? -> (I did my own helper and generate the html ... well I think there is a better way;-) -> do I have to overide text_field(object_name, method, parameters {}, options = {})
2006 Aug 19
5
Form helpers don''t work with facade columns?
Hello all, I''ve been trying to use a facade column but I notice that the form helpers don''t seem to respect the facade. In the following example I''m trying to story the prices as Integer values but present them to the user as decimals. class Product < ActiveRecord::Base def price=(new_price) write_attribute(:price, Float(new_price)*100) end def price
2006 Jan 12
1
Form Entity Names for Child Objects
In my controller, I do this to instantiate and populate my Part, PartName and PartNumber objects. def edit @part = Part.find(params[:id], :include => [:part_name, :part_number]) end But in the view, this doesn''t refer to the right object. I somehow need to indicate that the part_name object is a child of the part object. <%= text_field_with_auto_complete :part_name,
2006 Aug 09
0
Two Autocompletes, make first value affect the second
I have two text_field_with_auto_complete text_field_with_auto_complete :user, :state text_field_with_auto_complete :user, :suburb The user fills in the text_field_with autocomplete... but then I want to filter the results in the suburb with the value they''ve just entered def auto_complete_for_user_suburb @suburbs = PostCode.find(:all, :conditions => ["lower(locality)