Hi
I''m using link_to_remote, in a page that (as usual) needs to work for
non-js enabled browsers.
According to the API
-(http://www.railsbrain.com/api/rails-2.0.2/doc/index.html?a=M001827&name=link_to_remote),
i can pass an href option which points to a url which is called in the
non-js version.
In this case, i want the ajax call *and* the normal html link to go to
the same controller and the same action:
"selections/create?resource_id=x".
My problem is that i''m using restful routes and can''t seem
to work out
the syntax. Here''s what i *thought* it should be:
link_to_remote image_tag("/images/v4/basket.gif", :alt => "Add
to
basket"),
{ :url => selections_path(:resource_id => resource.id), :method =>
:post }, :href => url_for( :controller => "selections",
:action =>
"create", :resource_id => resource.id )
This works in the js case: the restful route of calling selections_path
with a POST request sends me to selections/create.
But the href option doesn''t work properly: it calls
"selections/index?resource_id=x"
Can i pass a restful route through to href as well? I''ve tried various
arrangements but it keeps breaking because of bad syntax. I have a
feeling that if i''m using a restful route helper i can drop url_for and
just point href at the helper but i can''t work the syntax out for that
either.
Can anyone help?
thanks
max
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
The :url syntax seems to be correct. BTW, href doesn''t support RESTful create action since create need to be POST. On Apr 3, 5:33 pm, Max Williams <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi > > I''m using link_to_remote, in a page that (as usual) needs to work for > non-js enabled browsers. > > According to the API > -(http://www.railsbrain.com/api/rails-2.0.2/doc/index.html?a=M001827&na...), > i can pass an href option which points to a url which is called in the > non-js version. > > In this case, i want the ajax call *and* the normal html link to go to > the same controller and the same action: > "selections/create?resource_id=x". > > My problem is that i''m using restful routes and can''t seem to work out > the syntax. Here''s what i *thought* it should be: > > link_to_remote image_tag("/images/v4/basket.gif", :alt => "Add to > basket"), > { :url => selections_path(:resource_id => resource.id), :method => > :post }, :href => url_for( :controller => "selections", :action => > "create", :resource_id => resource.id ) > > This works in the js case: the restful route of calling selections_path > with a POST request sends me to selections/create. > > But the href option doesn''t work properly: it calls > "selections/index?resource_id=x" > > Can i pass a restful route through to href as well? I''ve tried various > arrangements but it keeps breaking because of bad syntax. I have a > feeling that if i''m using a restful route helper i can drop url_for and > just point href at the helper but i can''t work the syntax out for that > either. > > Can anyone help? > thanks > max > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> I''m using link_to_remote, in a page that (as usual) needs to work for > non-js enabled browsers.You could play with format.html. That should be called when JS is not enabled. something like... format.html { redirect_to(resources_path) } ? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Max Williams
2008-Apr-03 10:21 UTC
Re: link_to_remote with href option - syntax help needed
Vapor .. wrote:>> I''m using link_to_remote, in a page that (as usual) needs to work for >> non-js enabled browsers. > > You could play with format.html. That should be called when JS is not > enabled. > something like... > > format.html { redirect_to(resources_path) } > > ?Hi Vapor I have my formats set up fine, like you suggest: the problem is that it doesn''t reach them because it gets sent to the wrong controller action (index instead of create) in the html case. All i need is a link that sends an ajax request *or* an html request to the same action and the same controller, depending on whether the user has js enabled. This must be a very common requirement for any site, which is why i''m going so crazy trying to work it out :( -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Max Williams
2008-Apr-03 10:28 UTC
Re: link_to_remote with href option - syntax help needed
Hi Ashchan> The :url syntax seems to be correct.hmmmm....in that case, can you see any other reason why it might request the index action instead of the create action.> BTW, href doesn''t support RESTful create action since create need to > be POST.I wasn''t sure about href, that''s why i explicity passed through the controller and action. It just seems to ignore the action though. I have a feeling this is just to do with arranging my {}s and () properly... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Try specifically setting :html => {:url => ...}
I''m not being RESTful, but this is working for me:
(link_to_remote ''«prev'',
:url => {:action => ''change_month'', :month =>
@date.last_month.month, :year => @date.last_month.year},
:html => {:href => url_for(:month =>
@date.last_month.month, :year => @date.last_month.year), :class =>
"otherMonthLink"})
Sorry that the lines are so long!
-Kyle
On Apr 3, 5:28 am, Max Williams
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Hi Ashchan
>
> > The :url syntax seems to be correct.
>
> hmmmm....in that case, can you see any other reason why it might request
> the index action instead of the create action.
>
> > BTW, href doesn''t support RESTful create action since create
need to
> > be POST.
>
> I wasn''t sure about href, that''s why i explicity passed
through the
> controller and action. It just seems to ignore the action though. I
> have a feeling this is just to do with arranging my {}s and ()
> properly...
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---