Home Download Buy Blog Forum Support

problem detecting scope for snippets in rails

problem detecting scope for snippets in rails

Postby bandola on Tue Jul 05, 2011 10:53 am

I been trying out Sublime text for a few days now, and so far I have really liked the experience.

The only thing that really bugging me is that I can't get autocomplete / snippets to work with Rails. It seems it is a problem with detecting the right scope. If I inside an .erb template add a ruby tag (<% bt %>). The snippet below work just fine. In my .rb files it doesn't.

<snippet>
<content><![CDATA[belongs_to :${1:object}${2:, :class_name => "${3:${1/[[:alpha:]]+|(_)/(?1::\u$0)/g}}", :foreign_key => "${4:${1}_id}"}]]></content>
<tabTrigger>bt</tabTrigger>
<scope>source.ruby.rails</scope>
<description>belongs_to</description>
</snippet>

I running Sublime build 2076, Mac OS X 10.6.7, Ruby 1.8.7 and Rails 3.0.7 (using RVM)

thanks
bandola
 
Posts: 6
Joined: Tue Jul 05, 2011 10:13 am

Re: problem detecting scope for snippets in rails

Postby jps on Tue Jul 05, 2011 11:02 am

Your snippet has a scope of 'source.ruby.rails', to make it work with plain Ruby files, you should change it to 'source.ruby'.

Also, if you are using the rails snippets, then some of them won't work properly (i.e., won't insert <% and %>) unless you're using build 2077, from http://www.sublimetext.com/dev
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: problem detecting scope for snippets in rails

Postby bandola on Tue Jul 05, 2011 12:00 pm

thanks jps for your fast reply.

I changed to 'source.ruby' and it works but it should be better if only the rails specific methods was available to use then I work on a rails project.

I do not know if you are using Rails ?
If not the snippet I posted create a belongs_to association in a Rails app and are only used inside the models. Models are unfortunately named as normal ruby files ( my_model.rb ) in rails.

It is not possible to get Sublime to distinguish between .rb files used as models and normal .rb files ?

Sorry for not making this clear in my previous question.

thanks again
bandola
 
Posts: 6
Joined: Tue Jul 05, 2011 10:13 am

Re: problem detecting scope for snippets in rails

Postby jps on Tue Jul 05, 2011 1:00 pm

If you change the syntax to Ruby on Rails (via View/Syntax/Rails/Ruby on Rails, or using the command palette), then it seems it gets assigned a scope of 'source.ruby.rails', which sounds like what you're after.
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: problem detecting scope for snippets in rails

Postby bandola on Tue Jul 05, 2011 2:05 pm

that did the trick!

If somebody else read this thread and need to change the syntax settings you can make them persistent by selecting syntax/open all with current extention as/ .

I did not figure that out at first.

thanks jps
bandola
 
Posts: 6
Joined: Tue Jul 05, 2011 10:13 am


Return to Technical Support

Who is online

Users browsing this forum: Saucebergenstein and 26 guests