SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 217 | Next

Ola Bini

"Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java"

In the same manner, the create method needs to call
form before rendering the new view:
def create
@article = Article.new(params[:article])
if @article.save
flash[:notice] = 'Article was successfully created.'
redirect_to :action => 'list'
else
form
render :action => 'new'
end
end
edit works the same way too:
def edit
@article = Article.find(params[:id])
form
end
Finally, edit the update method, which will change some when you add the ability to
preview an article. However, right now it should look like this:
def update
@article = Article.find(params[:id])
if @article.update_attributes(params[:article])
flash[:notice] = 'Article was successfully updated.'
redirect_to :action => 'list'
else
form
render :action => 'edit'
end
end
Once again, adding the invocation of the form method is the only thing that has changed.
Ideally, your controller should now be in good shape for working with articles, but you still
CHAPTER 7 ?–  A RAILS CMS 137
need to edit the views. The list view is close to the original, except that you only display
select elements. For example, it isn??™t a good idea to display the article content in the list:

Listing articles













<% for article in @articles %>

IDSubjectNameContent TypeLayoutPath
<%=h article.


Pages:
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229