Today's the day

向软件大牛炫耀我会焊单片机,向硬件大牛炫耀我会写 Rails,向软硬件大牛炫耀我生物,向软硬件生物大牛炫耀我会折腾期货 -_-bbb

respond_to 新构想
is-Programmer 升级到 Chito 1.0.7

修改下 In Place Editing 插件

galeki posted @ 2008年8月21日 15:45 in RoR with tags rails in place editing , 3989 阅读

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:

  1.     def in_place_edit_for(object, attribute, options = {})
  2.       define_method("set_#{object}_#{attribute}") do
  3.         @item = object.to_s.camelize.constantize.find(params[:id])
  4.         if @item.update_attributes({attribute.to_sym => params[:value]})
  5.             render :text => @item.send(attribute).to_s
  6.         else
  7.             render :text => @item.errors.on(attribute.to_sym)
  8.         end
  9.       end
  10.     end

也可以加个样式着重下错误信息:

  1. render :text => "<span style='color:red;'>#{@item.errors.on(attribute.to_sym)}</span>"

protect_from_forgery 的问题只要加上 authenticity_token 参数就可以了:

lib/in_place_macros_helper.rb:

  1.   def in_place_editor_field(...)
  2.     ...
  3.     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 })
  4.     ...
  5.   end

 这样就 OK 了,效果还不错:

 

UMAIR 说:
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.

UMAIR 说:
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

UMAIR 说:
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

UMAIR 说:
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

Elastic Dori Manufac 说:
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!

slotxo ทดลองเล่น 说:
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

Disposable Scrub Sui 说:
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!

Dalvin Smith 说:
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

Dalvin Smith 说:
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>

Soghat e Sheerin 说:
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

Dalvin Smith 说:
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

Dalvin Smith 说:
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

M Anus Raza 说:
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

Softech Source 说:
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

Dalvin Brown 说:
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

The Hiltonian 说:
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

The Hiltonian 说:
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

News Record 说:
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>

News Record 说:
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

Getmuzz 说:
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

Resume Builder 说:
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]

Hira Mart 说:
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

Hira Mart 说:
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

NE Calgary dentist 说:
2023年5月23日 21:34

I recently found much useful information on your website, especially this blog page. Among the lots of comments on your articles. Thanks for sharing. NE Calgary dentist

Dental Implants NE C 说:
2023年5月23日 23:11

This is a great article. I am very much pleased with your good work. You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.

acupuncture victoria 说:
2023年5月24日 20:27

I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.

Best Dentist NE Calg 说:
2023年6月01日 00:17

Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking.

NE Calgary dentist 说:
2023年6月01日 01:50

I recently found much useful information on your website, especially this blog page. Among the lots of comments on your articles. Thanks for sharing.

HR Software 说:
2023年6月01日 22:40

Find all-in-one HR management solution, including payroll software, with Team Suite! Sign up now and experience the comprehensive and efficient benefits of Team Suite!

Restaurant Software 说:
2023年6月03日 00:04

Sign up now for our easy-to-use Cloud-ready Point of Sale (POS) software designed for restaurants and take your business to the next level. Optimize your restaurant's operations and increase profitability with our reliable POS system.

St. Albert dentist 说:
2023年6月05日 21:37

Spot on with this article, I really think this website needs more attention. I'll probably be back to read more, thanks for the info.

Edmonton dentist 说:
2023年6月05日 23:10

I have recently started a blog, and the info you provide on this site has helped me greatly. Thanks for all of your time & work.

Dental Implants Sout 说:
2023年6月06日 00:12

What a fantabulous post this has been. . I am grateful to you and expect more number of posts like these. Thank you very much.

emergency dentist ca 说:
2023年6月06日 02:02

Excellent article.Very interesting to read. I really love to read such a nice article. Thanks! keep rocking.

Etobicoke dentist 说:
2023年6月06日 20:19

Thanks for a beautiful share. Your article has proven the hard work and experience you have got in this field. Brilliant.

emergency dentist Ed 说:
2023年6月07日 00:43

The website is looking a bit flashy and it catches the visitor's eyes. The design is pretty simple and has a good user-friendly interface.

dental implants Banf 说:
2023年6月14日 23:14

Exactly, you're very kind of us about comment!.

dental implants Simc 说:
2023年6月15日 01:02

The information you have posted is very useful. The sites you have referred was good. Thanks for sharing..

dental implants calg 说:
2023年6月15日 02:30

WESTWINDS OFFICE BEACON HILL OFFICE WE ARE OPEN 7 DAYS A WEEK FOR EMERGENCIES A Relaxing & Friendly Dental Practice At Apollo Dental, we offer a comprehensive list of general, cosmetic, orthodontic, and emergency treatment options. dental implants calgary nw

Calgary dentist 说:
2023年6月15日 22:08

I am definitely enjoying your website. You definitely have some great insight and great stories.

dental implants Oakv 说:
2023年6月15日 23:13

The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface.

Emergency Dentist SW 说:
2023年6月15日 23:36

Thank you so much Love your blog..

Best Dentist Toronto 说:
2023年6月16日 00:40

It was wondering if I could use this write-up on my other website, I will link it back to your website though. Great Thanks.

emergency dentist Ed 说:
2023年6月17日 00:07

The website is looking a bit flashy and it catches the visitor's eyes. The design is pretty simple and has a good user-friendly interface.

dental implants NE C 说:
2023年6月17日 01:37

Thank you very much for this great post.

Best Dentist NW Edmo 说:
2023年6月21日 02:57

Thank you very much for this great post.

dental implants St. 说:
2023年6月21日 23:30

The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface.

Toronto Dentist 说:
2023年6月22日 02:33

Excellent article.Very interesting to read. I really love to read such a nice article. Thanks! keep rocking.

emergency dentist Oa 说:
2023年6月22日 07:36

Pretty good I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Anyway, I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info.

Islamic school in Mi 说:
2023年7月03日 22:01

Thank you very much for this great post.

Calgary dentist 说:
2023年7月18日 00:30

Excellent and very exciting site. Love to watch. Keep Rocking.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter