Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Railscasts' complex forms - refactoring with LowPro
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Tim Chater  
View profile   Translate to Translated (View Original)
 More options 24 Jan 2008, 13:39
From: Tim Chater <t.cha...@gmail.com>
Date: Thu, 24 Jan 2008 05:39:15 -0800 (PST)
Local: Thurs 24 Jan 2008 13:39
Subject: Railscasts' complex forms - refactoring with LowPro
Hello

I'm sure some of you are familiar with Ryan Bates' weekly tutorials on
railscasts.com. A few months ago there was a three-part series
(episodes 73-75) about creating/editing multiple models in one form.
I'm trying to achieve the same but not use obtrusive things like
link_to_function.

Mostly this has been easy enough, but I'm not sure how to rewrite the
add_task_link function (which Ryan makes into a helper at the end of
episode 74):

# projects_helper.rb
def add_task_link(name)
  link_to_function name do |page|
    page.insert_html :bottom, :tasks, :partial => 'task', :object =>
Task.new
  end
end

How do I deal with this?

Thanks.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Chater  
View profile   Translate to Translated (View Original)
 More options 24 Jan 2008, 13:53
From: Tim Chater <t.cha...@gmail.com>
Date: Thu, 24 Jan 2008 05:53:46 -0800 (PST)
Local: Thurs 24 Jan 2008 13:53
Subject: Re: Railscasts' complex forms - refactoring with LowPro
I should point out that I have sort of been able to solve this by
amending the new action of the tasks controller and adding this to its
responds_to block:

format.js do
  render :update do |page|
    page.insert_html :bottom, :tasks, :partial => 'projects/
task', :object => Task.new
  end
end

The only problem with this is that I've used a remote link, so it's
had to go back to the server, rather than all be done client side as
it was before... is there another way?

On Jan 24, 1:39 pm, Tim Chater <t.cha...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Webb  
View profile   Translate to Translated (View Original)
 More options 24 Jan 2008, 14:25
From: "Dan Webb" <d...@danwebb.net>
Date: Thu, 24 Jan 2008 14:25:50 +0000
Local: Thurs 24 Jan 2008 14:25
Subject: Re: Railscasts' complex forms - refactoring with LowPro

> The only problem with this is that I've used a remote link, so it's
> had to go back to the server, rather than all be done client side as
> it was before... is there another way?

The add_task_link helper in that example returns some ugly
HTML/JavaScript.  That's a great example of something that looks
perfectly acceptable at the Ruby end but is in fact pretty damn nasty.

There's a few approaches you could take.  The first one would be to
clone one of the previous task chunks and appendChild to the form.  A
nice way to do this is write a behaviour that clones a copy as soon as
the page is loaded (while the form values are still blank) then makes
clones from that as needed.  The second is that you could basically do
what add_task_link does:

Event.addBehavior({
  '#add_task_link:click': function() {
    $('taskform').insert(<%= render(:partial => 'project/task', ...).to_json);
  }

});

Not that Im just calling render then to_json on the result to turn it
into a JS quoted string.  Third option would be to use DOM Builder.
I'd go with cloning nodes though, it seems cleaner.

--
Dan Webb
http://www.danwebb.net

aim: danwrong123
skype: danwrong


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Chater  
View profile   Translate to Translated (View Original)
 More options 24 Jan 2008, 17:31
From: Tim Chater <t.cha...@gmail.com>
Date: Thu, 24 Jan 2008 09:31:01 -0800 (PST)
Local: Thurs 24 Jan 2008 17:31
Subject: Re: Railscasts' complex forms - refactoring with LowPro

> I'd go with cloning nodes though, it seems cleaner.

I've gone with this and it works a treat.

Thanks for such a comprehensive reply!

Tim


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google