> 1) I like button_to_remote as an alias for submit_to_remote.
I've just posted a patch tohttp://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/58…
Applied (with button_to_remote being the primary, submit_to_remote
being the alias). Thanks!
> 3) Requiring all post/delete actions to be buttons is a personal
> choice that you're more than free to make for your project. It
> wouldn't fly with my designers at 37signals. Rails shouldn't be
> dictating how the UI of an application should look or feel.
Correct me if I'm wrong but a little CSS can make a button look like a
link and even behave like one (including a hover effect). I've only
tried it in Safari and FF3 for the moment but I think I remember that
it worked in IE6/7 just fine.
That seems to defeat the purpose of the change. Switching one hack for
another. I'm -1 on this.
> 4) I agree with koz's analysis of the fallback of link_to_remote. We
> have an even better way currently where you can set :url in the html
> options and thus get a different fallback.
I know that but you seem to misinterpret my intent. All I was
proposing was a sensible default in the event that the user has
JavaScript disabled. I made this suggestion because I'm a good boy
and I use link_to_remote almost exclusively for GET requests where the
URL of the link would mostly be the same as for the AJAX request.
Question to everyone: Would it make sense to only default the :href
attribute to the value of :url if the link_to_remote handles a GET
request but leave it at "#" for POST/PUT/DELETE since they're likely
to be wrong anyways?
I like the spirit of that. I kinda wonder if it becomes a little too
magical. Some times the fallback URL will be set, some times it won't.
And if the implementor hasn't considered this and used a respond_to
block, expecting that all calls will be JS, then the non-JS user will
just end up seeing JS fragment code as his reply. Which seems to be
worse than a link not doing anything.
I think the safest thing in this case is simply to do nothing unless
the implementor has explicitly decided to allow for fallback
scenarios. And if he has, it'll be no problem for him to add the :url
parameter himself.
Most of my applications aren't designed to work with JS turned off
anyway. In fact, I bet that the majority of Ajax applications out
there are just the same. The effort to make it work in non-JS mode is
not worth the energy considering the tiny constituency for most
people. Thus we should make that scenario as smooth and logical as
possible while still allowing for someone to make a non-JS fallback
work if they put in a little extra effort.
So how about the following idea:
We should abstract the current functionality and create an
AbstractJavaScriptGenerator that (maybe) provides common functionality
sits in as a parent for PrototypeGenerator, JQueryGenerator,
MooToolsGenerator, etc. In the config, we'd then have something like
config.action_view.javascript_framework = :whatever that defaults
to :prototype. Both, view helpers and RJS, should then use the methods
of the respective generator.
Moreover, we'd probably need to move each framework into its own
subdirectory in /public/javascripts and then modify the
javascript_include_tag :all to first load /public/
javascripts/:framework and then (non-recursively) load all other files
in the root.
I like that approach a lot. It definitely needs to be concrete,
though. So as we develop AbstractJavaScriptGenerator, we need to make
sure that it can span to be implemented as JQueryGenerator and
MooToolsGenerator or whatever. So a patch to core would be contingent
on the availability of at least 2 preferably 3 implementations of it.
I like config.action_view.javascript_generator as the option now that
we're going with *Generator as the class.
How about making it configurable like my other suggestion? We could
have something like config.action_view.use_unobtrusive_javascript =
true that modifies *_to_remote in that it removes the onclick/onsubmit
event and instead adds a default CSS class (e.g. "remote", but maybe
also configurable) so we can easily add our unobtrusive JS layer to it
(using lowpro or whatever).
If all the unobtrusive approach needs is a class, then why bother with
link_to_remote at all? Why not just use link_to and add the class?