Let??™s get on with doing the Rails side of things for it too!
Sequence Controller and Views
You??™ve created a library to handle your remote access to the enterprise bean. The only thing
left is creating something that uses it. So, let??™s create a SequencesController and the corresponding
views:
jruby script/generate controller Sequences index list
show reset next create
rm app/views/sequences/reset.rhtml
rm app/views/sequences/next.rhtml
rm app/views/sequences/create.rhtml
You??™ll design the mutating methods to do their mutation and then redirect back to the
current point, because it doesn??™t make any sense to have separate pages for these. This controller
should use the bb layout, and you need to have the index action redirect to the list
action. Further, you should protect the mutating operations so they only can be reached by
POST:
layout "bb"
def index
list
render :action => 'list'
end
CHAPTER 10 ?– AN EJB-BACKED RAILS APPLICATION 189
# GETs should be safe
# (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
verify :method => :post, :only => [ :reset, :next, :create ],
:redirect_to => { :action => :list }
The rest of the actions are simple:
def list
@sequences = SequenceManager.list(@user)
end
def show
@sequence = SequenceManager.get(params[:id], @user)
end
def reset
SequenceManager.reset(params[:id], @user)
flash[:notice] = "Have reset sequence '#{params[:id]}'."
redirect_to :action => :show, :id => params[:id]
end
def next
val = SequenceManager.
Pages:
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288