Patrick Reagan, Development Director, November 22, 2006
One of the features of Rails that makes it a great framework for building the next generation of "Web 2.0" applications is its tight integration with the
script.aculo.us JavaScript library. What this means for your application is the ability to dynamically update the display based on the results of an action (in this case '/task/mark_complete'):
def mark_complete
begin
@task = Task.find(params[:id])
@task.task_status_id = TaskStatus::COMPLETE
@task.save
rescue ActiveRecord::RecordNotFound
render :nothing => true
return
end
render_text @task.status.description
end
Adding this code in a view template is all we need to have our display automatically update:
Status:
<%= @task.status.description %>
<%= link_to_remote 'Mark as Complete',
:update =>, 'task-status-' + @task.id.to_s,
:url => {:controller => 'task', :action => 'mark_complete', :id => @task %>
This works great for those times when we only need to update a single DOM element on a page. What about when we need to update multiple pieces of content on the same page? One solution that has worked quite well for us is the use of
RJS templates in Rails.
Continue reading "Getting Started With RJS in Rails"
Recent Comments
Tony,
I understand and agree that the back-end shouldn’t output code (html code), and only content. The templates (aka views) should do the trick, but instead of having lot’s of if/else conditionals inside the view, you may just output the following content.
No information available
The template would loop in an array and put all the <li>’s inside the <ul>.
I don’t see anything wrong, nor...