Sublime Forum

Problem detecting scope for snippets in rails

#1

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.

"${3:${1/[[:alpha:]]+|(_)/(?1::\u$0)/g}}", :foreign_key => "${4:${1}_id}"}]]> bt source.ruby.rails belongs_to

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

thanks

0 Likes

#2

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 sublimetext.com/dev

0 Likes

#3

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

0 Likes

#4

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.

0 Likes

#5

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

0 Likes