I have following code in my view:
<% @m1.map(&:id).each do |id|%>
<%= b.fields_for :modul1hours do |f| %>
<%= f.hidden_field :modul1_id, id %>
<%= f.text_field :module_est_hours, :size => 30 %>
</tr>
<% end %>
<%end%>
params passing in console
Parameters: {"authenticity_token"=>"LJ/ZME2lHZ7VwCDgPKX6OFe326fXSXo5UB4M0cPwbCE=", "esthour"=>{"rfp_id"=>"6", "ecommerce_est_hours"=>"", "modul1hours"=>{"module_est_hours"=>"3"}, "designpages_est_hours"=>"", "cms_est_hours"=>""}, "modul1_ids"=>["12", "13", "14"], "utf8"=>"✓", "project_id"=>"second", "commit"=>"Add Todo"}
Current user: admin (id=1)
modul1_ids is the hidden array based on that three text box is created but when i submit the page gives me:
ActionView::Template::Error (undefined method `merge' for 12:Fixnum):
in first textbox i passed 1 second 2 and in third 3
last value(3) isthe s passing that one can see in the console params module_est_hours"=>"3
, but what about rest two fields y not passing and whats the solution for an error. Please help me.
Edit 1
<% @m1.map(&:id).each do |id|%>
<%= b.fields_for :modul1hours do |f| %>
<%= hidden_field_tag "modul1_ids[]", id %>
<%= f.text_field :module_est_hours, :size => 30 %>
</tr>
<% end %>
<%end%>
this code does not give the error, but also value is not stored in modul1hours
table
The field of the modul1hours
table are:
integer :modul1_id
decimal :module_est_hours
decimal :module_act_hours
integer :esthours_id
]
.rb
belongs_to :esthour
attr_accessible :module_est_hours,:module_act_hours
and controller
Update
def new
@esthour = Esthour.new
@gg = @esthour.modul1hours.build
@project = params[:project_id]
@rfp = params[:rfp_id]
@m1 = Modul1.where(:rfp_id => @rfp.id)
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @esthour }
end
end over Update # GET /project_todos/1/edit
def edit
@esthour = Esthour.find(params[:id])
end
def create
@project = params[:project_id]
@esthour = Esthour.new(params[:esthour])
user_params = params.select{|k,v| k.include?('esthour')}
respond_to do |format|
if @esthour.save
get_issue_attribute_param1(user_params)
format.html { redirect_to project_rfp_url(@project,@esthour.rfp_id), :notice => 'hours was successfully created.' }
format.json { render :json => @esthour, :status => :created, :location => @esthour }
else
format.html { render :action => "new" }
format.json { render :json => @esthour.errors, :status => :unprocessable_entity }
end
end
end
is there any build needed?eg Esthour.modul1hour.build in new def of controller coz record not saved in table?
view
<%= form_for @esthour,:rfp_id => @rfp.id,:project_id => @project do |b| %>
<%= b.hidden_field :rfp_id, :value => @rfp.id %>
<%= hidden_field_tag :project_id, @project %>
<table>
<tr> <td><b>Menutype </b></td>
<% if @rfp.menutype.present? %>
<td><%= @rfp.menutype %></td>
<td><%= b.number_field :menutype_est_hours %></td>
<% end %>
</tr>
<tr> <td> <b>Number of menu</b> </td>
<% if @rfp.numberofmenu.present? %>
<td><%= @rfp.numberofmenu %></td>
<td><%= b.number_field :numberofmenu_est_hours %></td>
<% end %>
</tr>
<tr>
<% @m1.map(&:id).each do |id|%>
<%= b.fields_for :modul1hours do |f| %>
<%= f.hidden_field :modul1_id, value => id %>
<%= f.text_field :module_est_hours, :size => 30 %>
</tr>
<% end %>
<% end %>
</table>
<%= b.submit 'Add Todo' %>
<% end %>
@esthour = Esthour.new
@gg = @esthour.modul1hours.build
@project = params[:project_id]