Hi everyone!
I''m new to Ruby and JS, and there is a problem I''m trying to
solve:
I need a link that, when clicked, transforms into a form for inputting
data. I have next code:
(show.html.erb)
<div id="new_journal">
<%= link_to_remote ''New Journal'',
:url => { :action => :expand_create_form, :controller
=> :journals, :user_id => @user.id } %>
</div>
(expand_create_form.js.rjs)
page[:new_journal].replace_html :partial => "create",
:object => @user
The problem is I don''t want to use the controller, is there some
shortcut to call rjs code when user clicks on "New Journal" link?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Felix
2009-Feb-19 08:35 UTC
Re: Clilking on a link should replace that link with a form...
You could do something like this:
<%= link_to_function ''New Journal'',
"Element.replace(this, #{ render
(:partial => "create",
:object => @user).inspect})"%>
check here for some gotchas with rendering partials this way:
http://tracesof.blogspot.com/2009/02/rails-partials-in-javascript-functions.html
Maybe a much nicer solution in this case would be to render the form
in a hidden div below the link and then just hide the link and un-hide
the form when the link is clicked. Like so:
<div id="new_journal">
<%= link_to_function ''New Journal'', "this.hide();
$
(''new_journal_form'').show()" %>
<div id="new_journal_form" style="display:none">
<%= render :partial => "create", :object => @user
%>
</div>
</div>
On Feb 18, 11:38 pm, Andrew
<registerons...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi everyone!
>
> I''m new to Ruby and JS, and there is a problem I''m trying
to solve:
> I need a link that, when clicked, transforms into a form for inputting
> data. I have next code:
>
> (show.html.erb)
> <div id="new_journal">
> <%= link_to_remote ''New Journal'',
> :url => { :action => :expand_create_form, :controller
> => :journals, :user_id => @user.id } %>
> </div>
>
> (expand_create_form.js.rjs)
> page[:new_journal].replace_html :partial => "create",
> :object => @user
>
> The problem is I don''t want to use the controller, is there some
> shortcut to call rjs code when user clicks on "New Journal" link?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Felix
2009-Feb-19 10:31 UTC
Re: Clilking on a link should replace that link with a form...
Ha, just thought of a much better way:
(show.html.erb)
<div id="new_journal">
<%= link_to_function ''New Journal'' do |page|
page[:new_journal].replace_html :partial => "create",
:object
=> @user
end %>
</div>
On Feb 19, 9:35 am, Felix
<felix.hage...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> You could do something like this:
>
> <%= link_to_function ''New Journal'',
"Element.replace(this, #{ render
> (:partial => "create",
> :object => @user).inspect})"%>
>
> check here for some gotchas with rendering partials this
way:http://tracesof.blogspot.com/2009/02/rails-partials-in-javascript-fun...
>
> Maybe a much nicer solution in this case would be to render the form
> in a hidden div below the link and then just hide the link and un-hide
> the form when the link is clicked. Like so:
>
> <div id="new_journal">
> <%= link_to_function ''New Journal'',
"this.hide(); $
> (''new_journal_form'').show()" %>
>
> <div id="new_journal_form"
style="display:none">
> <%= render :partial => "create", :object =>
@user %>
> </div>
> </div>
>
> On Feb 18, 11:38 pm, Andrew
<registerons...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > Hi everyone!
>
> > I''m new to Ruby and JS, and there is a problem I''m
trying to solve:
> > I need a link that, when clicked, transforms into a form for inputting
> > data. I have next code:
>
> > (show.html.erb)
> > <div id="new_journal">
> > <%= link_to_remote ''New Journal'',
> > :url => { :action => :expand_create_form, :controller
> > => :journals, :user_id => @user.id } %>
> > </div>
>
> > (expand_create_form.js.rjs)
> > page[:new_journal].replace_html :partial => "create",
> > :object => @user
>
> > The problem is I don''t want to use the controller, is there
some
> > shortcut to call rjs code when user clicks on "New Journal"
link?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Matt Jones
2009-Feb-20 01:46 UTC
Re: Clilking on a link should replace that link with a form...
Why are you opposed to using the controller? In any case, you can drop the RJS into app/views/journals/ expand_create_form.js.rjs and it should work. That *is* the shortcut... --Matt Jones On Feb 18, 5:38 pm, Andrew <registerons...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi everyone! > > I''m new to Ruby and JS, and there is a problem I''m trying to solve: > I need a link that, when clicked, transforms into a form for inputting > data. I have next code:...> > The problem is I don''t want to use the controller, is there some > shortcut to call rjs code when user clicks on "New Journal" link?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---