tracks/tracks/app/controllers/notes_controller.rb
lukemelia ba0b52ff1a Merged mobile_controller into the todos_controller. The lightweight mobile HTML is
arguably just another representation of the same resources, so it seems to fit
the RESTful Rails paradigm to use an extension (.m) to switch on in the
respond_to stanza.

I needed some hackery to make this work. See my note in todos_controller for
a full explanation.
 
I also added a route to get to the mobile view by using 'domain.com/m'

Created some selenium tests for the mobile view, too. 

In optimizing the data access for the mobile view, I ran into "a bug in rails
pagination":http://dev.rubyonrails.org/ticket/7885" and integrated a nice
pagination plugin from the Err the Blog guys
("will_paginate":http://errtheblog.com/post/929) to work around the issue.

NOTE that this changeset includes a new line in environment.rb.tmpl (at
the bottom). Be sure to copy this into your environment.rb file. 

These changes fix #489 (cannot edit action using mobile interface).
Thanks for the bug report, lrbalt!

In the name of consistency, I made the argument to the block for all
respond_to calls 'format' (instead of the formerly cool 'wants').

Lastly, I added a link to the project's new contribute page to the footer of
the main web UI. Help us join the Mac on Intel world. :-)



git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@517 a4c988fc-2ded-0310-b66e-134b36920a42
2007-04-02 04:18:19 +00:00

61 lines
1.3 KiB
Ruby

class NotesController < ApplicationController
def index
@all_notes = @user.notes
@page_title = "TRACKS::All notes"
respond_to do |format|
format.html
format.xml { render :xml => @all_notes.to_xml( :except => :user_id ) }
end
end
def show
@note = check_user_return_note
@page_title = "TRACKS::Note " + @note.id.to_s
end
# Add a new note to this project
#
def create
note = @user.notes.build
note.attributes = params["new_note"]
if note.save
render :partial => 'notes_summary', :object => note
else
render :text => ''
end
end
def destroy
note = check_user_return_note
if note.destroy
render :text => ''
else
notify :warning, "Couldn't delete note \"#{note.id.to_s}\""
render :text => ''
end
end
def update
note = check_user_return_note
note.attributes = params["note"]
if note.save
render :partial => 'notes', :object => note
else
notify :warning, "Couldn't update note \"#{note.id.to_s}\""
render :text => ''
end
end
protected
def check_user_return_note
note = Note.find_by_id( params['id'] )
if @user == note.user
return note
else
render :text => ''
end
end
end