I am trying to test drive RJS templates in Rails 1.2. Here is what I
did:
create table categories (name varchar(255) );
rails RJSTest
cd RJSTest
rake update_javascripts
script/generate controller home index add
script/generate model category
Note: When I did a rake update_javascripts, I did not see any output.
I configured database.yml to talk to mysql.
Next I wrote controller/home_controller.rb:
class HomeController < ApplicationController
def index
@categories = Category.find( :all )
end
def add
@category = Category.new
if request.post?
@category = Category.create( params[:category] )
end
end
end
Then I wrote views/home/index.rhtml:
<%= form_remote_tag :url => { :action => ''add'' }
%>
Category: <%= text_field ''category'',
''name'' %>
<%= submit_tag ''Add'' %>
<%= end_form_tag %>
<ul id="categories">
<% @categories.each do |category| -%>
<li><%= category.name %></li>
<% end -%>
</ul>
Then I wrote views/home/add.rjs:
if @category && @category.errors.empty?
li = content_tag( ''li'', @category.name )
page.insert_html :bottom, ''categories'', li
page.visual_effect :highlight, ''categories'', :duration =>
3
end
Now when I point my browser to http://localhost/home/index.rhtml, I see
my form and i can submit a category name. The add action in the
controller then goes to add.rhtml instead of add.rjs. Evidentally, I am
missing something!
Note: I can see that the categories are being created in the database. I
am just not being taken from the action to the rjs template.
Am running:
ruby 1.8.4 (2005-12-24) [i686-linux]
Rails 1.1.2
Using Webrick
OS: Ubuntu
Que 1: What am I missing or doing wrong?
Que 2: Am I right in understanding that Rails 1.2 has RJS template
support built in and I do not have to use edge rails?
Que 3: Is rake update_javascripts supposed to install javascript
libraries like prototype etc? If yes, when I execute that command should
I be seeing some output telling me whats being installed?
Thank you for sheding any light.
--
Posted via http://www.ruby-forum.com/.