PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, May 18, 2022

[FIXED] Why do I have this "undefined method form" with my RoR app?

 May 18, 2022     forms, partial, ruby-on-rails, ruby-on-rails-3     No comments   

Issue

I have a partial

= form.fields_for :cycles do |c|
  %tr{:style=>"border-right:none;"}
%td{:width=>"16%"}
  = c.text_field :day, :size=>6
  = c.hidden_field :id
%td{:width=>"35%"}= c.text_field :hour, :size=>15
%td{:width=>"35%"}= c.text_field :hour_night, :size=>15
%td{:style => "width:7%;padding:0;border-right:none",:align=>"center"}
  = c.hidden_field :_destroy
  = link_to image_tag("panel_tools/delete.png",:size=>"15x15"), nil, :href =>"", :onclick => "check_nested_attr_destroy(this);return false;" 

I call this from the view like this

= form_for(@schedule_of_working, @new_action ? {:url => schedule_of_workings_path} : {:url => schedule_of_working_path, :method=> :put}) do |f| 
.....
= render(:partial=>'cycles', :collection => @schedule_of_working.cycles, :locals => {:form => f}) if @schedule_of_working.cycles.count > 0

I'm getting an error about undefined method form..

rails -v 3.1.0


Solution

Rails only really works well when you follow its conventions.

You should avoid using: hidden fields, put with a form, passing in the action that way and I'm not sure what you are trying to do with the url in various parts, but anyway avoid these unless you have really good reason why you are not structuring it according to convention. Focus more on your routes and how resources are setup and your models and their relationships and your views should be very minimalist. In them I'm not sure what the hour and hour_night are, or theor length 15. Confusion mix of stuff.

So your form, as is, has a few problems. Rather than specific advice I would just say re-write it. It should be much simpler than this. I would recommend watching some railscasts on forms, e.g.
Forms Part one, two or three



Answered By - Michael Durrant
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing