开发者

Get Redmine custom field value to a file

I'm trying to create a text file that contains the value of a custom field I added on redmine. I tried to get it from an SQL query in the create method of the project_controller.rb (at line 80 on redmine 1.2.0) as follows :

sql = Mysql.new('localhost','root','pass','bitnami_redmine')
rq = sql.query("SELECT value 
   FROM custom_values 
   INNER JOIN projects
   ON custom_values.customized_id=projects.id
   WHERE custom_values.custom_field_id=7
   AND projects.name='#{@project.name}'")
rq.each_hash { |h|
  File.open('pleasework.txt', 'w') { |myfile|
    myfile.write(h['value'])
  }
}
sql.close

This works fine if I test it in a separate file (with an existing project name instead of @project.name) so it may be a syntax issue 开发者_JS百科but I can't find what it is. I'd also be glad to hear any other solution to get that value.

Thanks !

(there's a very similar post here but none of the solutions actually worked)


First, you could use Project.connection.query instead of your own Mysql instance. Second, I would try to log the SQL RAILS_DEFAULT_LOGGER.info "SELECT ..." and check if it's ok... And the third, I would use identifier instead of name.


I ended up simply using params["project"]["custom_field_values"]["x"] where x is the custom field's id. I still don't know why the sql query didn't work but well, this is much simpler and faster.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜