views:

193

answers:

3

Hi, I am using jQuery in my Rails App. But when I try to turn my button to jQueryUI(Cupertino theme) button, it does not appear to be look like a jQuery UI Themed button. jQuery works because I am using it for Ajax and it works properly. I have pasted the code. Please tell me whether I am doing it wrongly

<%=stylesheet_link_tag 'jquery-ui','scaffold'%>
<%=javascript_include_tag "jquery-1.4.2.min","jquery-ui-1.8.1.min","application"%>

<input type = submit id = "add" name = "add" value = " Add " />

The following code is in application.js file

$(document).ready(function() {
$("#add").button();
}

Thanks

+1  A: 

you need to place the javascript in a a script block that runs when the document has loaded and is ready :)

try:

<script type="text/javascript">
    $(document).ready(function () {
        $("#add").button();
    });
</script>
Alastair Pitts
Yea.The $("#add").button() call is in document.ready() function in application.js file :)
Felix
CSS? Have you included a jQueryUI CSS file? Otherwise the custom style won't get applied
Alastair Pitts
Yea... <%=stylesheet_link_tag 'jquery-ui','scaffold'%>Updated the question too...Thanks :)
Felix
do you have a place where we can try this out? Or local dev box only?
Alastair Pitts
Hey, I just have a local dev :(. The css code that should be included to the "add" button is somehow not getting added.Now when I include the code for the $("#add").button() inside a document.ready in a script tag, jquery-ui css gets applied and works.Why it is so?.
Felix
Is it possible that the order of the JS includes was incorrect? (not really knowing how ruby does it)
Alastair Pitts
+1  A: 

Are you including both stylesheets? jQueryUI base .css as well as your theme's .css?

Ken Browning
I am including two stylesheets. One is the jquery-ui theme and the other one is the scaffold.css that comes with the rails app
Felix
If you're using a theme with jQuery UI then you will reference two stylesheets. base and theme.
Ken Browning
Oh is it like that? But I included the jquery-ui in a html file, when I was just playing around with jquery ui. I included it like this (<link type="text/css" rel="stylesheet" href="jquery-ui.css">)and it worked. I did not included two separate files for base and theme
Felix
A: 

I am sorry guys...Thanks for the effort. It was a typo in my application.js file that stopped all the js in that file...:( Sorry for wasting your time

Felix
@Steve: Great to hear there was a resolution. :) Don't forget to mark this as the answer
Alastair Pitts