Do they get called and raise an error do they not get called at all? Is the page loading at all? Are you using Firefox? Do you have Firebug? What is Firebug telling you about the AJAX request? Do you like cheese on toast? What’s the square root of 24… the questions are endless.
I think you should have a create.html.erb file incase the user does
not have javascript turned on.
In the controller you have the respond_to
respond_to do |format|
format.js #create.js.rjs
format.html #create.html.erb
end
or a more detailed version . . .
respond_to do |format|
if @task.save
format.html do
flash[:notice] = 'Task was successfully created.'
redirect_to{ (@task)
end
format.js
else
format.html { render :action => "new" }
format.js { render :template => "shared/error.js.rjs" }
end
end
(in the js.rjs file)
page.insert_html :bottom, 'tasks', :partial => @task # adds new
task into the partial
page['task_form'].reset #
resets the form
page.visual_effect :highlight, "task_#{@task.id}", #
highlights the just added div that has the new task
:startcolor => '#336699'
I use a partial in my index.html.erb view.
<div id="tasks">
<%= render :partial => @tasks %>
</div>
_task.html.erb file
<% div_for task do %>
<%= h(task.name) %>
<% end %>
the div_for task do gives the div an id = to task_1 (or what ever the
id of the task is.)
Example:
I have one task that has an id of 1
I add a new task. It gets an id of 2
In the rjs
1) It adds a new div, with an id = task_2, into the div on the index
view that has the id of "tasks".
2) It clears the form with the reset.
3) highlight the task_2
I'm having the same problems, except I can't even seem to get any of
the effects to work or calls like 'page.call :my_function'. I've got
an index.html.erb file, and an index.hs.rjs file. The js.rjs file just
has:
page.visual_effect :highlight, "my_div"
and my controller has:
respond_to do |format|
format.js { render :template => "index.js.rjs" }
end
But whatever I do I can't seem to make this work. It always complains
with the try/catch error that has something like "alert('RJS error:\n
\n' + e.toString())". I've also tried changing the page.visual_effect
to a page.call, and I cant make this work either. Any ideas?
Why the hell did this change in rails 2.0 anyway, what was wrong with
the way it worked, where you could just do:
render :update do |page|
page.call :alert, "Im js"
end
And not have to worry about creating a stupid js.rjs file.