Rails running methods inappropriately - ruby-on-rails-4

A rails controller defines a before_action
before_action :set_intervento, only: [ ... ]
to
def set_intervento
#intervento = Intervento.find(params[:id])
end
But my action risultati_fatturati is not listed in the only block. yet error Couldn't find Intervento with 'id'=risultati_fatturatiis being generated where Rails justifying itself as having to run the set_intervento method. What else is at work here that is launching the method?
EDIT
routes show
resources :interventos do
collection do
get :indexmio
get :indexmio_programmati
get :passati
get :non_assegnati
get :programmati
get :domani
get :domani_e_dopo
get :settimana
get :planning
get :in_corso
get :successivi
get :successivo
get :passati_da_eseguire
get :articolo_adhoc
get :calendar
post :calendarc
get :settimanale
get :chiusi
post :ripresa
get :risultati_articolos
get :risultati_ordina_articolos
get :creare_checklist
post :neuter_ddt
post :cancel_ddt
get :elenco_ddt
get :dispatcher_check
get :manager_list
get :manager_comments
post :manager_check_required
get :preventivi_attivi
get :cerca_fatturati
get :non_fatturabili
post :risultati_fatturati
get :cerca_chiusi
post :risultati_chiusi
post :duplicate_intervento
get :ordinari_chiusi
get :ordinari_aperti
end
member do
get :pdfc
get :create_pdf_rapporto
get :refresh_pause_intervento
get :refresh_close_intervento
patch :update_successivo
patch :update_ddt
patch :materials_sucessivo
patch :materials_availability
patch :preventivare
patch :esito_preventivo
patch :scaduto_preventivo
patch :ripristina_preventivo
get :dispatcher_fix
patch :dispatcher_signature
get :correzione_fattura
end
end
Translating to
indexmio_interventos GET /interventos/indexmio(.:format) interventos#indexmio
indexmio_programmati_interventos GET /interventos/indexmio_programmati(.:format) interventos#indexmio_programmati
passati_interventos GET /interventos/passati(.:format) interventos#passati
non_assegnati_interventos GET /interventos/non_assegnati(.:format) interventos#non_assegnati
programmati_interventos GET /interventos/programmati(.:format) interventos#programmati
domani_interventos GET /interventos/domani(.:format) interventos#domani
domani_e_dopo_interventos GET /interventos/domani_e_dopo(.:format) interventos#domani_e_dopo
settimana_interventos GET /interventos/settimana(.:format) interventos#settimana
planning_interventos GET /interventos/planning(.:format) interventos#planning
in_corso_interventos GET /interventos/in_corso(.:format) interventos#in_corso
successivi_interventos GET /interventos/successivi(.:format) interventos#successivi
successivo_interventos GET /interventos/successivo(.:format) interventos#successivo
passati_da_eseguire_interventos GET /interventos/passati_da_eseguire(.:format) interventos#passati_da_eseguire
articolo_adhoc_interventos GET /interventos/articolo_adhoc(.:format) interventos#articolo_adhoc
calendar_interventos GET /interventos/calendar(.:format) interventos#calendar
calendarc_interventos POST /interventos/calendarc(.:format) interventos#calendarc
settimanale_interventos GET /interventos/settimanale(.:format) interventos#settimanale
chiusi_interventos GET /interventos/chiusi(.:format) interventos#chiusi
ripresa_interventos POST /interventos/ripresa(.:format) interventos#ripresa
risultati_articolos_interventos GET /interventos/risultati_articolos(.:format) interventos#risultati_articolos
risultati_ordina_articolos_interventos GET /interventos/risultati_ordina_articolos(.:format) interventos#risultati_ordina_articolos
creare_checklist_interventos GET /interventos/creare_checklist(.:format) interventos#creare_checklist
neuter_ddt_interventos POST /interventos/neuter_ddt(.:format) interventos#neuter_ddt
cancel_ddt_interventos POST /interventos/cancel_ddt(.:format) interventos#cancel_ddt
elenco_ddt_interventos GET /interventos/elenco_ddt(.:format) interventos#elenco_ddt
dispatcher_check_interventos GET /interventos/dispatcher_check(.:format) interventos#dispatcher_check
manager_list_interventos GET /interventos/manager_list(.:format) interventos#manager_list
manager_comments_interventos GET /interventos/manager_comments(.:format) interventos#manager_comments
manager_check_required_interventos POST /interventos/manager_check_required(.:format) interventos#manager_check_required
preventivi_attivi_interventos GET /interventos/preventivi_attivi(.:format) interventos#preventivi_attivi
cerca_fatturati_interventos GET /interventos/cerca_fatturati(.:format) interventos#cerca_fatturati
non_fatturabili_interventos GET /interventos/non_fatturabili(.:format) interventos#non_fatturabili
risultati_fatturati_interventos POST /interventos/risultati_fatturati(.:format) interventos#risultati_fatturati
cerca_chiusi_interventos GET /interventos/cerca_chiusi(.:format) interventos#cerca_chiusi
risultati_chiusi_interventos POST /interventos/risultati_chiusi(.:format) interventos#risultati_chiusi
duplicate_intervento_interventos POST /interventos/duplicate_intervento(.:format) interventos#duplicate_intervento
ordinari_chiusi_interventos GET /interventos/ordinari_chiusi(.:format) interventos#ordinari_chiusi
ordinari_aperti_interventos GET /interventos/ordinari_aperti(.:format) interventos#ordinari_aperti
pdfc_intervento GET /interventos/:id/pdfc(.:format) interventos#pdfc
create_pdf_rapporto_intervento GET /interventos/:id/create_pdf_rapporto(.:format) interventos#create_pdf_rapporto
refresh_pause_intervento_intervento GET /interventos/:id/refresh_pause_intervento(.:format) interventos#refresh_pause_intervento
refresh_close_intervento_intervento GET /interventos/:id/refresh_close_intervento(.:format) interventos#refresh_close_intervento
update_successivo_intervento PATCH /interventos/:id/update_successivo(.:format) interventos#update_successivo
update_ddt_intervento PATCH /interventos/:id/update_ddt(.:format) interventos#update_ddt
materials_sucessivo_intervento PATCH /interventos/:id/materials_sucessivo(.:format) interventos#materials_sucessivo
materials_availability_intervento PATCH /interventos/:id/materials_availability(.:format) interventos#materials_availability
preventivare_intervento PATCH /interventos/:id/preventivare(.:format) interventos#preventivare
esito_preventivo_intervento PATCH /interventos/:id/esito_preventivo(.:format) interventos#esito_preventivo
scaduto_preventivo_intervento PATCH /interventos/:id/scaduto_preventivo(.:format) interventos#scaduto_preventivo
ripristina_preventivo_intervento PATCH /interventos/:id/ripristina_preventivo(.:format) interventos#ripristina_preventivo
dispatcher_fix_intervento GET /interventos/:id/dispatcher_fix(.:format) interventos#dispatcher_fix
dispatcher_signature_intervento PATCH /interventos/:id/dispatcher_signature(.:format) interventos#dispatcher_signature
correzione_fattura_intervento GET /interventos/:id/correzione_fattura(.:format) interventos#correzione_fattura
interventos GET /interventos(.:format) interventos#index
POST /interventos(.:format) interventos#create
new_intervento GET /interventos/new(.:format) interventos#new
edit_intervento GET /interventos/:id/edit(.:format) interventos#edit
intervento GET /interventos/:id(.:format) interventos#show
PATCH /interventos/:id(.:format) interventos#update
PUT /interventos/:id(.:format) interventos#update
DELETE /interventos/:id(.:format) interventos#destroy
and the controller action
def risultati_fatturati
date = params[:intervento]
#date_start = Date.civil(date["dal(1i)"].to_i, date["dal(2i)"].to_i, date["dal(3i)"].to_i)
#date_end = Date.civil(date["al(1i)"].to_i, date["al(2i)"].to_i, date["al(3i)"].to_i)
if !params[:intervento][:invoicestate_id].blank?
#interventos = Intervento.joins(:signatures).where(['signatures.created_at >= ? AND signatures.created_at <= ? AND signatures.sequence = ? AND interventos.invoicestate_id = ?', #date_start.at_beginning_of_day, #date_end.at_end_of_day, "fine", params[:intervento][:invoicestate_id]]).paginate :page => params[:page], :per_page => 100
else
#interventos = Intervento.joins(:signatures).where(['signatures.created_at >= ? AND signatures.created_at <= ? AND signatures.sequence = ?', #date_start.at_beginning_of_day, #date_end.at_end_of_day, "fine"]).paginate :page => params[:page], :per_page => 100
end
render layout: "application"
end
so the action is within a collection and does not call #intervento. This is why I find it strange.
Edit #2
Side note: attempted to remove the before_action and find the member in each action, leading to identical results. Thus there is a deeper cause.
In an attempt to view things differently and understand via triangulation, I attempted a theoretically simpler process. That of running a partial for updating each record
<%= render "stato_fatturazione", intervento: intervento %>
whose form calls a specific action, which will invoke Rails's ujs
<%= form_for stato_fatturazione_intervento_path(intervento), method: :patch, remote: true, data: {disable_with: "Aggiornando..."} do |f| %>
Alas, notwithstanding the parameters, that have the proper path for editing, rails is attempting to patch the page with the array of records, which is by definition unpatchable, and leads to the same Couldn't find Intervento with 'id'=risultati_fatturati
Started PATCH "/interventos/risultati_fatturati" for ::1 at 2017-07-31 10:52:14 +0200
Processing by InterventosController#update as JS
Parameters: {"utf8"=>"✓", "/interventos/123/stato_fatturazione"=>{"invoicestate_id"=>"3", "in_zucchetti"=>"475", "fatturato"=>"1"}, "commit"=>"Aggiorna", "id"=>"risultati_fatturati"}
The rendered HTML does confirm the target action is being intercepted by some method:
<form data-disable-with="Aggiornando..." action="/interventos/risultati_fatturati" accept-charset="UTF-8" data-remote="true" method="post">

Related

Renaming parameters in nested resources

In Rails 4.2.6, I am creating nested resources like this
routes.rb:
resources :analysis, param: :project_id do
resources :configuration
end
resources :decision, param: :project_id do
resources :configuration
end
It works fine when I am in the analysis or decision controller. However, when I am in the configuration controller, I receive the param :analysis_project_id or :decision_project_id. How can I change this so I still receive :project_id?
I don't want to customize my configuration controller to be aware that it is nested in different resources.
just this, you need not to send params over here, It will take automatically with corresponding to your action.
resources :analysis do
resources :configuration
end
if you need routes like these
analysis_configuration_index GET /analysis/:analysis_id/configuration(.:format) configuration#index
POST /analysis/:analysis_id/configuration(.:format) configuration#create
new_analysis_configuration GET /analysis/:analysis_id/configuration/new(.:format) configuration#new
edit_analysis_configuration GET /analysis/:analysis_id/configuration/:id/edit(.:format) configuration#edit
analysis_configuration GET /analysis/:analysis_id/configuration/:id(.:format) configuration#show
PATCH /analysis/:analysis_id/configuration/:id(.:format) configuration#update
PUT /analysis/:analysis_id/configuration/:id(.:format) configuration#update
DELETE /analysis/:analysis_id/configuration/:id(.:format) configuration#destroy
analysis_index GET /analysis(.:format) analysis#index
POST /analysis(.:format) analysis#create
new_analysis GET /analysis/new(.:format) analysis#new
edit_analysis GET /analysis/:id/edit(.:format) analysis#edit
analysis GET /analysis/:id(.:format) analysis#show
PATCH /analysis/:id(.:format) analysis#update
PUT /analysis/:id(.:format) analysis#update
DELETE /analysis/:id(.:format) analysis#destroy
EDITED 13 Aug 2020
To get the specific param in nested resources
resources :analysis, param: :project_id do
member do
resources :configurations
end
end
resources :decision, param: :project_id do
member do
resources :configurations
end
end
Expected routes
configurations GET /analysis/:project_id/configurations(.:format) configurations#index
POST /analysis/:project_id/configurations(.:format) configurations#create
new_configuration GET /analysis/:project_id/configurations/new(.:format) configurations#new
edit_configuration GET /analysis/:project_id/configurations/:id/edit(.:format) configurations#edit
configuration GET /analysis/:project_id/configurations/:id(.:format) configurations#show
PATCH /analysis/:project_id/configurations/:id(.:format) configurations#update
PUT /analysis/:project_id/configurations/:id(.:format) configurations#update
DELETE /analysis/:project_id/configurations/:id(.:format) configurations#destroy
analysis_index GET /analysis(.:format) analysis#index
POST /analysis(.:format) analysis#create
new_analysis GET /analysis/new(.:format) analysis#new
edit_analysis GET /analysis/:project_id/edit(.:format) analysis#edit
analysis GET /analysis/:project_id(.:format) analysis#show
PATCH /analysis/:project_id(.:format) analysis#update
PUT /analysis/:project_id(.:format) analysis#update
DELETE /analysis/:project_id(.:format) analysis#destroy
GET /decisions/:project_id/configurations(.:format) configurations#index
POST /decisions/:project_id/configurations(.:format) configurations#create
GET /decisions/:project_id/configurations/new(.:format) configurations#new
GET /decisions/:project_id/configurations/:id/edit(.:format) configurations#edit
GET /decisions/:project_id/configurations/:id(.:format) configurations#show
PATCH /decisions/:project_id/configurations/:id(.:format) configurations#update
PUT /decisions/:project_id/configurations/:id(.:format) configurations#update
DELETE /decisions/:project_id/configurations/:id(.:format) configurations#destroy
decisions GET /decisions(.:format) decisions#index
POST /decisions(.:format) decisions#create
new_decision GET /decisions/new(.:format) decisions#new
edit_decision GET /decisions/:project_id/edit(.:format) decisions#edit
decision GET /decisions/:project_id(.:format) decisions#show
PATCH /decisions/:project_id(.:format) decisions#update
PUT /decisions/:project_id(.:format) decisions#update
DELETE /decisions/:project_id(.:format) decisions#destroy

VCR is not recording cassettes on successful requests, only on failed ones

I have a simple test to fetch one Facebook object. I'm using Curl for the request.
it "gets an object from Facebook" do
VCR.use_cassette('facebook') do
url = "https://graph.facebook.com/<ID>?access_token=#{#access_token}&#{query_string}"
curl = Curl::Easy.perform(url)
expect(curl.body_str).to eql('<my object>')
end
end
My VCR configs are:
VCR.configure do |c|
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
c.hook_into :webmock
end
When I run the tests, it passes, and the following is logged:
[Cassette: 'facebook'] Initialized with options: {:record=>:once, :match_requests_on=>[:method, :uri], :allow_unused_http_interactions=>true, :serialize_with=>:yaml, :persist_with=>:file_system}
[webmock] Handling request: [get https://graph.facebook.com/<ID>?access_token=<TOKEN>&fields=%5B%22id%22,%22account_id%22,%22name%22,%22campaign_group_status%22,%22objective%22%5D] (disabled: false)
[Cassette: 'facebook'] Initialized HTTPInteractionList with request matchers [:method, :uri] and 0 interaction(s): { }
[webmock] Identified request type (recordable) for [get https://graph.facebook.com/<ID>?access_token=<TOKEN>&fields=%5B%22id%22,%22account_id%22,%22name%22,%22campaign_group_status%22,%22objective%22%5D]
But the cassette is not recorded and the dir is empty. I've tried :record => :all to same results.
Usually, people encountered this error when using incompatible hooks for the library they're using, but that's not the case. I'm using webmock and curb.
Curiously, the cassette is recorded when there's a failure in the request, e.g., the token is expired. When it's fixed, and I delete the file, it's not recorded again.
Have anyone had the same problem?
It turns out that my code was a little more complicated than above and was executing a callback after perfoming the request. Something like:
success_handler = Proc.new { return c.body_str }
curl.on_success do |easy|
success_handler.call(easy)
end
That bypasses VCR and the file is not written. Refactoring the code to not use callbacks works.

Rails 4 - Circular dependency detected while autoloading constant Users::TodosController

besides using devise for authentification w standard Devise routes.. , I added the follwoing
namespace :users do
resources :todos
end
to magane todos for the current user.
the generated routes are fine ...
users_todos GET /users/todos(.:format) users/todos#index
POST /users/todos(.:format) users/todos#create
new_users_todo GET /users/todos/new(.:format) users/todos#new
edit_users_todo GET /users/todos/:id/edit(.:format) users/todos#edit
users_todo GET /users/todos/:id(.:format) users/todos#show
PATCH /users/todos/:id(.:format) users/todos#update
PUT /users/todos/:id(.:format) users/todos#update
DELETE /users/todos/:id(.:format) users/todos#destroy
once the user is logged in , he is redirected to his todos#index list .. (users_todos_url)
def after_sign_in_path_for(resource)
....
elsif resource.is_a?(User) && Settings.permit_user_login
stored_location_for(resource) || users_todos_url
....
but then , the error is raised .... and it's stated in the log :
Started GET "/users/todos" for 127.0.0.1 at 2014-07-22 14:29:15 +0200
LoadError - Unable to autoload constant Users::TodosController, expected /Users/yves/bitbucket/railsTests/todoapp/app/controllers/users/todos_controller.rb to define it:
I have a users/todo_controller.rb
class User::TodosController < ApplicationController
..
def index
sort_order = "updated_at DESC , title"
todos = Todo.where(:user_id => current_user[:id]).order(sort_order).page params[:page]
end
Log says todo s _controller.rb.
Controller names are plural form.

Quick Multiple calls to Firebase crashes Rails

My controller pushes data to firebase on certain clicks.
class FirebaseController < ApplicationController
Firebase.base_uri = "https://firebaseProject.Firebaseio.com/"
def call_to_firebase
Firebase.push("firebase_channel", "firebase_data".to_json)
respond_to do |format|
format.json { render nothing: true, :status => 204 }
end
end
end
In case of quick successive calls to this controller, which is called on a click, my Puma server crashes immediately.
I am using Rails 4.0.0
Puma 2.6.0
Ruby 2.0.0
Below is a part of the huge log report generated.
ETHON: started MULTI
ETHON: performed EASY url= response_code=200 return_code=got_nothing total_time=2.663048
/Users/siddharthbhagwan/.rvm/gems/ruby-2.0.0-p247/gems/ethon-0.6.1/lib/ethon/multi/operations.rb:171: [BUG] Segmentation fault
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.3.0]
-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/CrashReporter
* /Library/Logs/CrashReporter
* ~/Library/Logs/DiagnosticReports
* /Library/Logs/DiagnosticReports
the more detail of.
-- Control frame information -----------------------------------------------
c:0091 p:---- s:0489 e:000488 CFUNC :multi_perform
c:0090 p:0018 s:0484 e:000483 METHOD /Users/siddharthbhagwan/.rvm/gems/ruby-2.0.0-p247/gems/ethon-0.6.1/lib/ethon/multi/operations.rb:171
c:0089 p:0034 s:0479 e:000478 METHOD /Users/siddharthbhagwan/.rvm/gems/ruby-2.0.0-p247/gems/ethon-0.6.1/lib/ethon/multi/operations.rb:160
c:0088 p:0036 s:0474 e:000473 METHOD /Users/siddharthbhagwan/.rvm/gems/ruby-2.0.0-p247/gems/ethon-0.6.1/lib/ethon/multi/operations.rb:43
c:0087 p:0020 s:0470 e:000469 METHOD /Users/siddharthbhagwan/.rvm/gems/ruby-2.0.0-p247/gems/typhoeus-0.6.6/lib/typhoeus/hydra/runnable.rb:21
c:0086 p:0008 s:0466 e:000465 METHOD /Users/siddharthbhagwan/.rvm/gems/ruby-2.0.0-p247/gems/typhoeus-0.6.6/lib/typhoeus/hydra/memoizable.rb:51
c:0085 p:0104 s:0463 e:000462 METHOD /Users/siddharthbhagwan/.rvm/gems/ruby-2.0.0-p247/gems/firebase-0.1.4/lib/firebase/request.rb:50
c:0084 p:0019 s:0456 e:000455 METHOD /Users/siddharthbhagwan/.rvm/gems/ruby-2.0.0-p247/gems/firebase-0.1.4/lib/firebase/request.rb:20
c:0083 p:0019 s:0451 e:000450 METHOD /Users/siddharthbhagwan/.rvm/gems/ruby-2.0.0-p247/gems/firebase-0.1.4/lib/firebase.rb:34
.
.
.
c:0005 p:0027 s:0029 e:000028 METHOD /Users/siddharthbhagwan/.rvm/gems/ruby-2.0.0-p247/gems/puma-2.6.0/lib/puma/server.rb:357
c:0004 p:0035 s:0022 e:000021 BLOCK /Users/siddharthbhagwan/.rvm/gems/ruby-2.0.0-p247/gems/puma-2.6.0/lib/puma/server.rb:250 [FINISH]
c:0003 p:---- s:0016 e:000015 CFUNC :call
c:0002 p:0084 s:0011 e:000010 BLOCK /Users/siddharthbhagwan/.rvm/gems/ruby-2.0.0-p247/gems/puma-2.6.0/lib/puma/thread_pool.rb:92 [FINISH]
c:0001 p:---- s:0002 e:000001 TOP [FINISH]
.
.
.
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
Abort trap: 6
By quick I mean one click per second. This doesnt happen for slower clicks like 1 click per 2 seconds.
Pushing to firebase from the irb in a loop doesn't cause this error.
Thanks in Advance,
Cheers!
Are you using firebase-ruby gem? I submitted a bug fix for this issue today. You can hot patch it yourself by overriding the problematic method in the gem like so:
module Firebase
class Request
def process(method, path, body=nil, query_options={})
request = Typhoeus::Request.new(build_url(path),
:body => body,
:method => method,
:params => query_options)
response = request.run
Firebase::Response.new(response)
end
end
end
Or wait for the pull request to be accepted. The problem was in the gem's use of Typheous' Hydra.

GRAILS: Can I call service logic from _FORM.GSP template?

I'm refactoring scaffolding templates and I hit a wall with this issue:
I was trying to call service (some security logic) from template _FORM.GSP - but in the code part, not in the output part
I've read and tried what was suggested in here: How do I call a Grails service from a gsp?
I've tried to use taglib, but my knowledge of grails may not be extensive enough for that
I've tried add import and def to the beginning of _FORM.GSP file (both grailsApplication and application instantiation of service were crashing on missing property application resp. missing property grailsApplication)
I've even tried to call the taglib from the code both directly as method isAllowedToEdit and also as g.isAllowedToEdit both crashing on unknown method resp. "no such property g"
it seems that template _form.gsp has different rules than standard gsp view
I want to do something like this:
private renderFieldForProperty(p, owningClass, prefix = "") {
boolean hasHibernate = pluginManager?.hasGrailsPlugin('hibernate')
boolean display = true
boolean required = false
if (hasHibernate) {
cp = owningClass.constrainedProperties[p.name]
display = (cp ? cp.display : true)
required = (cp ? !(cp.propertyType in [boolean, Boolean]) && !cp.nullable && (cp.propertyType != String || !cp.blank) : false)
}
/* trying to do this part */
// I want to assign value to cp.editable - so later I can render read-only fields in renderEdit
if (!mySecurityService.canEdit(springSecurityService.currentUser, owningClass.getClass(), actionName, p.name)) {
cp.editable = false
}
/* trying to do this part */
if (display) { %>
<div class="fieldcontain \${hasErrors(bean: ${propertyName}, field: '${prefix}${p.name}', 'error')} ${required ? 'required' : ''}">
<label for="${prefix}${p.name}">
<g:message code="${domainClass.propertyName}.${prefix}${p.name}.label" default="${p.naturalName}" />
<% if (required) { %><span class="required-indicator">*</span><% } %>
</label>
${renderEditor(p)}
</div>
<% } } %>
if there is any way to assign cp.editable - I'll try your suggestions
it seems that template _form.gsp has different rules than standard gsp view
The generated _form.gsp works same as other gsps but the template inside the scr/templates/scaffolding/ is different. Customizing the templates like you are doing is a bit more tricky. Keep in mind that the logic you are writing is for Grails on how to generate views(gsp). Meaning you are telling Grails to check some logic before generating the views in memory or in the file. You might be able to accomplish that to some extend for dynamic (in memory) scaffolding at run-time but for sure not for static scaffolding. That's because Grails
is not aware of currentUser when generating the templates.
Your problem will be much simpler if you generate your views and then customize them instead of modifying their templates. Then you can inject your services and do other checks. However, as you also mentioned those logics are better off in a tag library here.
Also since you mentioned security, rendering a field non-editable does not guaranty inability to edit your fields. I would suggest to put the check logic inside your controller for example in SAVE or UPDATE action to prevent any unauthorized user editing fields.
Did you try this?
<%# page import="com.myproject.MyService" %>
<%
def myService = grailsApplication.classLoader.loadClass('com.myproject.MyService').newInstance()
%>
this will work for sure.
go through this link : click here