Posted by shane
on Thursday, January 19
I ran into a situation while working on a side project, where I needed to update a few elements on the page after performing an in-place edit. This can happen in a situation where what you are editing is also displayed elsewhere on the page. You don’t want to confuse the user by having the old value as well as the new value on the same page. This can be accomplished with RJS templates and some slight modifications to the Rails in-place editor macro.
NOTE: RJS templates are like RHTML templates, but for Javascript. As of this post, this feature is only available in the current Rails trunk and is not part of the 1.0 release. You need to be on EdgeRails to use them.
First, define a method in the controller that will replace the Rails in\_place\_edit_for macro. To in-place edit the ‘name’ attribute of a model named ‘Event,’ do:
1
2
3
4
5
6
7
8
|
def set_event_name
@event = Event.find(params[:id])
previous_name = @event.name
@event.name = params[:value]
@event.name = previous_name unless @event.save
# include logic needed for partials in RJS template
end |
Then create a new file in the view folder called set\_event\_name.rjs. This needs to include the partial containing the in-place editor view code, as well as anything else you need to update on the page.
1
2
3
4
|
page.replace_html 'in_place_edit_results', :partial => "desc"
page.replace_html 'upcoming', :partial => "upcoming"
page.visual_effect :highlight, 'upcoming', :duration => 1
page.replace_html 'month', :partial => "month" |
The view, _desc.rhtml, can use the built-in Rails macro helper:
<%= in_place_editor_field :event, :name %>
Check out this great article if you need to validate and sanitize the data.
Posted by shane
on Sunday, January 15
When you start a new Rails project using the rails generator, it creates a shebang line in dispatch.fcgi specific to where ruby is installed. For example, on FreeBSD, the line is
#!/usr/local/bin/ruby18
On Mac OS X, the line is
#!/opt/local/bin/ruby
I use FreeBSD in my production environment and OS X in my development environment. Instead of maintaining two different dispatch.fcgi files or adding extra logic to the files, you can easily solve this problem by making a symlink in the development environment.
I first changed the line to the appropriate one for my production environment, and then created the following symlink.
sudo ln /usr/local/bin/ruby18 /opt/local/bin/ruby
This is probably more of an issue for people on vastly different platforms. However, since FreeBSD and OS X are so similar, I might just standardize on /usr/local/bin/ruby.
Posted by shane
on Sunday, January 15
I really don’t like the new name of Apple’s first Intel notebook. Powerbook just sounds so much cooler, why change the name? I believe this is an attempt by Apple’s marketing department to strengthen the Mac brand. I’m not a marketing expert, but I believe Apple has way too many sub-brands in its hardware line, which can confuse newcomers. iBook, PowerBook, iMac, Power Mac, which is the right one for me?
Is a PowerBook a Mac? Believe it or not, some people might not know this. Calling the new notebook a MacBook puts it right in the name. Now the average consumer does not need to associate “PowerBook” or “iBook” with “Mac.” I think Apple tried to move in this direction with the “i” prefix brands, so people would know iAnything was an Apple product.
Which is better, an iBook or a PowerBook? Standardizing on MacBook and MacBook Pro will settle the issue.
I still don’t like new name, but I’m sure it will grow on me as I subconsiously get bombared with ads. Lets hope there won’t be a MacPod.