RJS Failing

This code was working before I created the update_link_list method in
the helper below (everything was in the controller). I can successfully
create a new link but I get a TypeError when I leave all form fields
blank – I expect to see validation error messages.


#link_controller.rb:

def create
link = Link.new(params[:link])
saved = link.save
num_links = Link.find(:all).size
num_cats = Category.find(:all).size
if request.xhr?
render:update do |page| page.update_link_list(link, saved,
num_links, num_cats) end
return
end
if saved
flash[:message] = ‘Link was successfully created.’
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end


#link_controller helper:

def update_link_list(new_link)
if @saved
page[‘listing-status’].replace_html “You’ve created
#{@num_links} links in #{@num_cats} categories”
page[‘no-links’].remove if @num_links == 1 && page[‘no-links’]
page.insert_html :after, “category-#{new_link.category_id}”,
:partial => ‘link’, :object => new_link
page.visual_effect :highlight, “link-#{new_link.id}”
page.replace_html ‘new_link_error’, ‘’
page[‘link_url’].value = ‘http://’
page[‘link_name’].value = ‘’
page[‘link_description’].value = ‘’
else # not saved, present error messages
page.replace_html ‘new_link_error’, error_messages_for(new_link)
page.visual_effect :appear, ‘new_link_error’, :duration => 0.5
page.visual_effect :highlight, ‘new_link_error’, :duration =>
0.5
end
end


I’m receiving this error:

TypeError in Publish/linksController#create

ActionView::Helpers::JavaScriptProxy#to_str should return String

No clue how to fix this. Any ideas? Many thanks…

Greg

Greg wrote:


#link_controller helper:

def update_link_list(new_link)
if @saved
page[‘listing-status’].replace_html “You’ve created
#{@num_links} links in #{@num_cats} categories”
page[‘no-links’].remove if @num_links == 1 && page[‘no-links’]
page.insert_html :after, “category-#{new_link.category_id}”,
:partial => ‘link’, :object => new_link
page.visual_effect :highlight, “link-#{new_link.id}”
page.replace_html ‘new_link_error’, ‘’
page[‘link_url’].value = ‘http://’
page[‘link_name’].value = ‘’
page[‘link_description’].value = ‘’
else # not saved, present error messages
page.replace_html ‘new_link_error’, error_messages_for(new_link)
page.visual_effect :appear, ‘new_link_error’, :duration => 0.5
page.visual_effect :highlight, ‘new_link_error’, :duration =>
0.5
end
end


Ooops … should be this (apologies):

def update_link_list(new_link, was_saved, num_links, num_cats)
if was_saved
page[‘listing-status’].replace_html “You’ve created #{num_links}
links in #{num_cats} categories”
page[‘no-links’].remove if num_links == 1 && page[‘no-links’]
page.insert_html :after, “category-#{new_link.category_id}”,
:partial => ‘link’, :object => new_link
page.visual_effect :highlight, “link-#{new_link.id}”
page.replace_html ‘new_link_error’, ‘’
page[‘link_url’].value = ‘http://’
page[‘link_name’].value = ‘’
page[‘link_description’].value = ‘’
else # not saved, present error messages
page.replace_html ‘new_link_error’, error_messages_for(new_link)
page.visual_effect :appear, ‘new_link_error’, :duration => 0.5
page.visual_effect :highlight, ‘new_link_error’, :duration =>
0.5
end
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs