修改下 In Place Editing 插件
In Place Editing 这个插件代码非常简洁,却方便的实现了即时编辑的效果,不过自从从 Rails 的核心移出去之后,貌似就没有再升级过。
首先它不支持 Validate,In Place Editing 的保存不经过检查,即使你 validates_presence_of :name,也可以在 In Place Editing 中把 name 清空并保存,而且这样做了之后,由于 name 没有了文字,也没法点击编辑了。
另外它也不支持 protect_from_forgery。
虽说有个 REST In Place 插件,似乎是 In Place Editing 的替代品,其实稍微修改一下,In Place Editing 就能重放光芒了~
没法 validate 的缘故是因为它用了 update_attribute 的方法更新属性,只要改成 update_attributes 就可以了,然后检查保存是否成功,如果失败,将错误信息显示出来:
lib/in_place_editing.rb:
-
def in_place_edit_for(object, attribute, options = {})
-
define_method("set_#{object}_#{attribute}") do
-
@item = object.to_s.camelize.constantize.find(params[:id])
-
if @item.update_attributes({attribute.to_sym => params[:value]})
-
render :text => @item.send(attribute).to_s
-
else
-
render :text => @item.errors.on(attribute.to_sym)
-
end
-
end
-
end
也可以加个样式着重下错误信息:
-
render :text => "<span style='color:red;'>#{@item.errors.on(attribute.to_sym)}</span>"
protect_from_forgery 的问题只要加上 authenticity_token 参数就可以了:
lib/in_place_macros_helper.rb:
-
def in_place_editor_field(...)
-
...
-
in_place_editor_options[:url] = in_place_editor_options[:url] || url_for({ :action => "set_#{object}_#{method}", :authenticity_token => form_authenticity_token, :id => tag.object.id })
-
...
-
end
这样就 OK 了,效果还不错:
2021年1月20日 18:18
JKBOSE Model Paper 2021: Sample papers not only gives a starting point to the students for where to begin but also helps in revising the vast syllabus within a time frame. Moreover, it serves equally well as a checklist which in turn helps to check whether all the topicsJKBOSE 12th Model Paper 2021 have been covered. And working smarty while revising the syllabus makes the difference between the toppers and among average students. So this time to help you to prepare for the exams from all aspects, here we are sharing all the possible sets of JK Board Previous Papers.
2021年1月30日 14:13
You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent. Thank you sa gaming
2021年2月02日 19:59
You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent. Thank you slilpp xyz shops search
2021年3月10日 14:41
You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent. Thank you pakseo.net
2021年9月01日 17:06
I love the humor your post has offered. I enjoyed this site a lot. Keep posting article like this. It is fun. Nice photography too!
2021年9月13日 18:35
You have done a great job. I will definitely dig it and personally recommend to my friends. I am confident they will be benefited from this site
2021年10月02日 18:26
This is exactly what I was looking for. Thanks for sharing this great article! That is very interesting Smile I love reading and I am always searching for informative information like this!
2021年10月22日 13:23
That gives off an impression of being brilliant anyway i am still not very beyond any doubt that I like it. At any rate will look significantly more into it and choose by and by! type iir surgical disposable face mask surgical disposable mask Disposable Scrub Suits elastic earloop earloop elastic
2021年11月24日 17:49
Your blogs further more each else volume is so entertaining further serviceable It appoints me befall retreat encore. I will instantly grab your rss feed to stay informed of any updates.
<a href="https://sinparty.yolasite.com/">free porn party</a>
2022年3月29日 18:47
This is some thing very informative and point to point. There is no round and round in this article. Like this smplicity . This clears my old point of view. THANKS Soghat-e-Sheerin Soghat Sweet Soghat Bakers Saloni Soghat Soghat Pizza
2022年4月24日 17:33
That gives off an impression of being brilliant anyway i am still not very beyond any doubt that I like it. At any rate will look significantly more into it and choose by and by! The Hiltonian Business News Entertainment News World News
2022年4月24日 22:55
I haven't any word to value this post.....Really i am awed from this post....the individual who make this post it was an extraordinary human..thanks for imparted this to us. The Hiltonian The Hiltonian World News Entertainment News World News
2022年5月23日 07:38
That gives off an impression of being brilliant anyway i am still not very beyond any doubt that I like it. At any rate will look significantly more into it and choose by and by! Breaking News Breaking News Breaking News Breaking News Breaking News
2022年9月05日 18:41
Nicely well-written article. It was an awesome article to read. Complete rich content and fully informative Softech Source App Development Company Web Development Company Ecommerce Website Development Company Best Digital Marketing Company SEO
2022年9月05日 19:37
Nicely well-written article. It was an awesome article to read. Complete rich content and fully informative Softech Source App Development Company Web Development Company Ecommerce Website Development Company Best Digital Marketing Company SEO
2022年9月19日 14:27
Nicely well-written article. It was an awesome article to read. Complete rich content and fully informative Business News World News Entertainment News Tech News Health News
2022年9月20日 00:23
Nicely well-written article. It was an awesome article to read. Complete rich content and fully informative tranny tube shemale tubes skyward fbisd fbisd skyward cam newton net worth 2021
2022年9月24日 22:59
Nicely well-written article. It was an awesome article to read. Complete rich content and fully informative News Record News And Record Greens Boro News Record Gillette News Record Daily News Record Greensboro News and Record Times Record News Daily News Record Obituaries
2022年9月26日 10:18
This is some thing very informative and point to point. There is no round and round in this article. Like this smplicity . This clears my old point of view. THANKS
<a href="https://newsrecord.co.uk/shooting-games-unblocked/">unblocked shooting games</a>
<a href="https://newsrecord.co.uk/bird-box-2-what-to-expect-from-the-upcoming-sequel/">bird box 2 release date uk</a>
<a href="https://newsrecord.co.uk/bird-box-2-what-to-expect-from-the-upcoming-sequel/">bird box 2 release date</a>
<a href="https://newsrecord.co.uk/behind-the-ear-tattoos/">behind the ear tattoos men</a>
<a href="https://newsrecord.co.uk/behind-the-ear-tattoos/">ear tattoos men</a>
2022年9月26日 10:18
This is some thing very informative and point to point. There is no round and round in this article. Like this smplicity . This clears my old point of view. THANKS unblocked shooting games bird box 2 release date uk bird box 2 release date behind the ear tattoos men ear tattoos men
2022年9月29日 10:32
Visit Omega World News for up-to-the-minute news, breaking news, and feature stories. Omega World News provides trusted World and Much More Omega World News Omega World News Omega World News Omega World News Omega World News Omega World News Omega World News Omega World News Omega World News Omega World News Latest Breaking News Latest Breaking News Latest Breaking News Latest Breaking News Latest Breaking News Breaking News Breaking News Breaking News Breaking News Breaking News
2022年10月24日 17:56
Breaking News & Top Stories. Latest breaking news and information on the top stories, weather, business, entertainment, politics and many more. Getmuzz
2022年11月23日 18:37
There are numerous dissertation websites on-line because you additionally obtain obviously stated inside your web site.
[url=https://resumebuilderr.com/]Resume Builder[/url]
2022年11月30日 18:50
We Provide Halal Products Only! Hira Mart All products in our shop are Muslim-friendly, so you can buy with confidence
2022年12月04日 14:57
We Provide Halal Products Only! Hira Mart All products in our shop are Muslim-friendly, so you can buy with confidence