Created
March 26, 2010 18:39
-
-
Save oren/345225 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
the plugin: | |
http://github.com/tamoyal/simple_time_select#readme | |
in the view: (u don't have to use date_select, but i needed it) | |
<%= f.date_select :published_at %> | |
<%= f.time_select :published_at, | |
{ :default => Time.now.change(:hour => Time.now.hour), | |
:simple_time_select => true, | |
:minute_interval => 30, | |
:time_separator => ""} %> | |
in the controller: | |
def update | |
params[:post] = fix_post_attrs(params[:post]) if params[:post] | |
@post = Post.find(params[:id]) | |
respond_to do |format| | |
if @post.update_attributes(params[:post]) | |
flash[:notice] = 'Post was successfully updated.' | |
format.html { redirect_to(@post) } | |
format.xml { head :ok } | |
else | |
format.html { render :action => "edit" } | |
format.xml { render :xml => @post.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
private | |
def fix_post_attrs(post_attrs) | |
if full_time = post_attrs.delete("published_at(5i)") | |
post_attrs.merge!( {'published_at(4i)' => Time.parse(full_time).hour.to_s} ) | |
post_attrs.merge!( {'published_at(5i)' => Time.parse(full_time).min.to_s} ) | |
end | |
post_attrs | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment