tag:blogger.com,1999:blog-74616481409873409712023-06-20T06:54:37.408-07:00Rails HangoverJason's Odysseyhttp://www.blogger.com/profile/13544941246445799313noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-7461648140987340971.post-34741982661363493062007-12-06T10:45:00.001-08:002007-12-06T10:47:35.333-08:00mysql database errno:145log in to ssh<br /><br />then<br /><br />mysql -u dbuname -h dbhost -p dbname;<br /><br />mysql -u jason -p tracker<br /><br />repair table nuke_bbsearch_wordmatch;<br /><br />fixes the problemJason's Odysseyhttp://www.blogger.com/profile/13544941246445799313noreply@blogger.com0tag:blogger.com,1999:blog-7461648140987340971.post-30460013270563567922007-11-27T07:58:00.000-08:002007-11-27T08:50:53.315-08:00Trouble with Ajax.in_place_select_editor for relationshipsUsing the scriptaculous in place editor controls is cool and very web 2.0, but the examples and documentation are far too simplistic to actually figure out how to do anything useful. So I bought the new book by Pragmatic Programming 'Prototype and Scriptaculous'.<br /><br />I was very dismayed that on the chapter dealing with Ajax.in_place_select, the example cut short on how to deal with setting up an in place editor for a drop down with a related table. Sure it has simple drop downs, but when you want to relate an 'id' and 'value' back to the control, you are going to have problems because the built in objects to deal with this stuff will not work the way you would expect.<br /><br />on the text that you would click to activate the control, which will display the initial value, it will display your 'id', not the value. Once you activate the control, it will display the human value, and save back to the server the id selected. Then it will display the id again, not the human value.<br /><br />I want it to display the human value, not the ID. Thats why we have a relational database in the first place!<br /><br />To get this to work you have to dive into making helper files to define your own control helpers, and you have to rewrite the way your control<br /><br />in your application.rb controler<br /><br /><br /><span style="font-family:courier new;">def in_place_related_list_editor_field(object,method, tag_options = {}, in_place_editor_options={})<br />tag = ::ActionView::Helpers::InstanceTag.new(object, method, self)<br />tag_options = { :tag => "span",<br />:id => "#{object}_#{method}_#{tag.object.id}_in_place_editor",<br />:class => "in_place_editor_field"}.merge!(tag_options)<br />in_place_editor_options[:url] =<br />in_place_editor_options[:url]<br />url_for({ :action => "set_#{object}_#{method}", :id => tag.object.id })<br />jtag="<span class="'in_place_editor_field'" id="'#{object}_#{method}_#{tag.object.id}_in_place_editor'">" + tag_options.delete(:show) + "</span>"<br />return jtag + in_place_collection_editor(tag_options[:id], in_place_editor_options)<br />end</span><br /><span style="font-family:Courier New;"></span><br /><br /><span style="font-family:courier new;">def in_place_collection_editor(field_id, options = {})<br />function = "new Ajax.InPlaceCollectionEditor("<br />function << "'#{field_id}'," function << "'#{url_for(options[:url])}'," js_options = {} js_options['cancelText'] = %('#{options[:cancel_text]}') if options[:cancel_text] js_options['okText'] = %('#{options[:save_text]}') if options[:save_text] js_options['loadingText'] = %('#{options[:loading_text]}') if options[:loading_text] js_options['savingText'] = %('#{options[:saving_text]}') if options[:saving_text] js_options['rows'] = options[:rows] if options[:rows] js_options['cols'] = options[:cols] if options[:cols] js_options['size'] = options[:size] if options[:size] js_options['externalControl'] = "'#{options [:external_control]}'" if options[:external_control] js_options['loadTextURL'] = "'#{url_for(options[:load_text_url])}'" if options[:load_text_url] js_options['ajaxOptions'] = options[:options] if options[:options] js_options['evalScripts'] = options[:script] if options[:script] js_options['callback'] = "function(form) { return #{options[:with]} }" if options[:with] js_options['clickToEditText'] = %('#{options[:click_to_edit_text]}') if options[:click_to_edit_text] collection = options[:select_options].inject([]) do options, element options << "[ '#{html_escape(element.last.to_s)}', '#{html_escape(element.first.to_s)}']" end js_options['collection'] = "[#{collection.join(',')}]" function << ( options_for_javascript(js_options)) unless js_options.empty? function << ');' javascript_tag(function) end</span><br /><br />and in the show:<br /><br />%= in_place_related_list_editor_field :contact, :contact_type_id, {:show =>@contact.contact_type.name}, :external_control=>'contact_type_id_ext',:select_options => ContactType.to_dropdown(:value => "name",:text => "name"), :rows => 1, :cols =>50 %><br /><br /><span style="font-family:courier new;">With a greater than before the % above.<br /><%= in_place_related_list_editor_field :contact, :contact_type_id, {:show =>@contact.contact_type.name}, :external_control=>'contact_type_id_ext',:select_options => ContactType.to_dropdown(:value => "name",:text => "name"), :rows => 1, :cols =>50 %></span><br /><span style="font-family:courier new;"></span><br /><br /><span style="font-family:courier new;"></span>Jason's Odysseyhttp://www.blogger.com/profile/13544941246445799313noreply@blogger.com0