Ruby on Rails Tuesday, May 17, 2011

here is the taskschedule#new view

<%= form_for @taskschedule, :url=>taskschedules_path do |f| %>
<p>Area: <%= f.text_field :name %></p>
<% for service in Service.find(:all) %>
<p><%= check_box_tag :service_ids, service.id,
@taskschedule.services.include?(service), :name =>
'taskschedule[service_ids][]' -%> <%= service.name %></p>

<% end %>
<%= submit_tag "Submit" %>
<% end -%>

as you can see i am assigning services to the taskschedule through the
model "area". that works.
the problem is i have a textfield in the model area that i want to
fill over this view. i tried fields_for(:area) but get an error
message?
thanks,
ed

On May 17, 5:02 pm, Bryan Crossland <bacrossl...@gmail.com> wrote:
> Sent from my iPhone
>
> On May 17, 2011, at 1:58 PM, eddyjab <edja...@gmail.com> wrote:
>
> > i understand. i have 3 models. taskschedule, services and areas. each
> > taskschedule has many services through the model area.
>
> > when i add(create/update) services to taskschedule i want to enter
> > also some information to the model area. hope that makes sence.
> > thanks
> > ed
>
> So what are you stuck on? What problem are you looking to get an answer for?
>
> B.
>
>
>
>
>
>
>
> > On May 17, 2:33 pm, David Kahn <d...@structuralartistry.com> wrote:
> >> On Tue, May 17, 2011 at 9:50 AM, eddyjab <edja...@gmail.com> wrote:
> >>> hi there,
> >>> i thing i just have a logical problem.
>
> >>> i have following models.
>
> >>> class Area < ActiveRecord::Base
> >>>        belongs_to :taskschedule
> >>>        belongs_to :service
> >>> end
>
> >>> class Service < ActiveRecord::Base
> >>>        has_many :taskschedules, :through => :areas
> >>>        has_many :areas
> >>> end
>
> >>> class Taskschedule < ActiveRecord::Base
> >>>        has_many :services, :through => :areas
> >>>        has_many :areas
> >>> end
>
> >>> Following View
>
> >>> Taskschedule#new
> >>> <h2>New Taskschedule</h2>
>
> >>> <%= form_for @taskschedule, :url=>taskschedules_path do |f| %>
> >>>        <p>Area: <%= f.text_field :name %></p>
> >>>        <% for service in Service.find(:all) %>
> >>>                <p><%= check_box_tag :service_ids, service.id,
> >>> @taskschedule.services.include?(service), :name =>
> >>> 'taskschedule[service_ids][]' -%> <%= service.name %></p>
>
> >>>        <% end %>
> >>>        <%= submit_tag "Submit" %>
> >>> <% end -%>
>
> >>> Taskschedule Controller
> >>> class TaskschedulesController < ApplicationController
> >>>        def index
> >>>                @taskschedules = Taskschedule.find(:all)
> >>>        end
>
> >>>        def new
> >>>                @taskschedule = Taskschedule.new
> >>>                @taskschedule.build.build_area
> >>>        end
>
> >>>        def create
> >>>                @taskschedule = Taskschedule.new(params[:taskschedule])
> >>>                if @taskschedule.save
> >>>                        redirect_to taskschedules_path
> >>>                end
> >>>        end
>
> >>>        def edit
> >>>                @taskschedule = Taskschedule.find(params[:id])
> >>>        end
>
> >>>        def update
> >>>                @taskschedule = Taskschedule.find(params[:id])
> >>>                if @taskschedule.update_attributes(params[:taskschedule])
> >>>                        redirect_to taskschedules_path
> >>>                else
> >>>                        render 'edit'
> >>>                end
> >>>        end
>
> >>> end
>
> >>> i have a text_field in areas that i want to be able to use in the
> >>> taskschedule#new view?
>
> >> The syntax of your question looks like a statement. What is your question?
> >> You are making whoever reads your question have to put thought into what you
> >> mean to ask.
>
> >>> Thanks for any help.
> >>> ed
>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups
> >>> "Ruby on Rails: Talk" group.
> >>> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> >>> To unsubscribe from this group, send email to
> >>> rubyonrails-talk+unsubscribe@googlegroups.com.
> >>> For more options, visit this group at
> >>>http://groups.google.com/group/rubyonrails-talk?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> > To post to this group, send email to rubyonrails-talk@googlegroups.com.
> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment