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
For translating strings you can use Rails I18n backend instead of using inflectors.
The `typus_human_name` is a patch to fix a problem in `human_name` [1].
[1] https://rails.lighthouseapp.com/projects/8994/tickets/2120-humanize-and-human_name-dont-separate-words