Question

i have a problem with redmine. In fact, i've created a model who use ActiveResource :

require 'active_resource'

class New < ActiveResource::Base
  #self.site = "http://localhost:3000/"
  #self.format = :xml
  #self.user = 'admin'
  #self.password = 'admin'

  class << self
    attr_accessor :api_key
  end

    def save
      prefix_options[:api_key] = self.class.api_key
    super
    end
end


New.site = 'http://localhost:3000'

New.api_key = '471bea6d1c4452b82b57287a281ff04392ae4118'

nw = New.new(:field_1 => 'value 1')
nw.save


# Retrieving news
news = New.find(:all)
puts news.first.title


#Retrieving an new
new = New.find(1)
puts new.description
puts new.author.name

# Creating an new
new = New.new(
:project_id => 1,
:author_id => 1,
:title => 'Annonce',
:summary => 'Annonce',
:description => 'Annonce'
)
if new.save
  puts new.id
else
  puts new.errors.full_messages
end

# Updating an 'new'
new = New.find(1)
new.title = 'NEW INFO '
new.save

# Deleting an new
new = New.find(1)
new.destroy

I'v an error 404 and i don't understand why:

/Users/bj/.rvm/gems/ruby-1.9.3-p429/gems/activeresource-4.0.0/lib/active_resource/connection.rb:144:in `handle_response': Failed.  Response code =404.  Response message = Not Found . (ActiveResource::ResourceNotFound)

PS: If i use api key or if i use self.site i've a 404 too !

Can you help me please? I tried many things but no every things doesn't works. Thanks for your answers !

Was it helpful?

Solution

The basic problem seems to be, that Redmine is not responding the way ActiveResource expects it. This could be due to changes in Rails 3, that where not properly reflected in Redmine yet.

The best option for you would maybe be dropping ActiveResource for something like httparty. You should also known, that Redmine currently only supports fetching all news (/news.json) and all news within a project (/projects/test_project/news.json). Neither fetching a single news directly nor creating or updating news is supported via the REST API.

Edit: The actual cause for the 404 in your code is due to the fact, that ActiveResource tried to POST to /news.json which is - as I have mentioned above - not supported by the REST API. If you remove the save call, you will run into another issue, where ActiveResource is not able to deserialize the response in New.find(:all). This lead me to think, that Redmine and ActiveResource are currently incompatible. Also the demo code in the Redmine wiki to create an issue, does not work for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top