I created controllers of project and task and appropraite html pages for
them and created two partials of fields and tasks and having link in
fields partial, when i call it it is throwing RJS error, please find the
code below and mention a solution for geting text box dynamically…
My Html page
<% form_for :project, :url => projects_path do |f| %>
<%= render :partial => ‘fields’, :locals => { :f => f } %>
<%= submit_tag "Create Project" %>
<% end %>Fields Partial
<%= error_messages_for :project %>
Name: <%= f.text_field :name %>
<%= link_to_function('Add') do |page| page.visual_effect :highlight, 'tasks' end%>
Task partial
<% @task = task %>
<%= error_messages_for :task %>
Task: <%= task_form.text_field :name %> <%= link_to_function "remove", "$(this).up('.task').remove()" %>
<% end %>My controller
class ProjectsController < ApplicationController
def index
@projects = Project.find(:all)
end
def new
@project = Project.new
@project.tasks.build
end
def create
@project = Project.new(params[:project])
if @project.save
flash[:notice] = “Successfully created project and tasks.”
redirect_to projects_path
else
render :action => ‘new’
end
end
def edit
@project = Project.find(params[:id])
end
def update
params[:project][:existing_task_attributes] ||= {}
@project = Project.find(params[:id])
if @project.update_attributes(params[:project])
flash[:notice] = “Successfully updated project and tasks.”
redirect_to project_path(@project)
else
render :action => ‘edit’
end
end
end