Giter Site home page Giter Site logo

inherited_resources's Introduction

Active Admin

Active Admin is a Ruby on Rails framework for creating elegant backends for website administration.

Version Github Actions Coverage Tidelift

Goals

  • Enable developers to quickly create good-looking administration interfaces.
  • Build a DSL for developers and an interface for businesses.
  • Ensure that developers can easily customize every nook and cranny.

Getting started

For enterprise

Active Admin for enterprise is available via the Tidelift subscription. Learn More.

Want to contribute?

If you want to contribute through code or documentation, the Contributing guide is the best place to start. If you have questions, feel free to ask.

Want to support us?

If you want to support us financially, you can help fund the project through a Tidelift subscription. By buying a Tidelift subscription you make sure your whole dependency stack is properly maintained, while also getting a comprehensive view of outdated dependencies, new releases, security alerts, and licensing compatibility issues.

You can also support us with a weekly tip via Liberapay.

Finally, we have an Open Collective where you can become a backer or sponsor for the project, and also submit expenses to it.

Dependencies

We try not to reinvent the wheel, so Active Admin is built with other open source projects:

Security contact information

Please use the Tidelift security contact to report a security vulnerability. Tidelift will coordinate the fix and disclosure.

Acknowledgements

Thanks to Greg Bell for creating and sharing this project with the open source community.

Thanks to all the people that ever contributed through code or other means such as bug reports, issue triaging, feature suggestions, code snippet tips, Slack discussions and so on.

Thanks to Tidelift and all our Tidelift subscribers.

Thanks to Open Collective and all our Open Collective contributors.

inherited_resources's People

Contributors

alejandroperea avatar ashanbrown avatar atd avatar carlosantoniodasilva avatar dcrec1 avatar deivid-rodriguez avatar dependabot-preview[bot] avatar dependabot[bot] avatar dmitri-wm avatar dougo avatar ellenvb avatar fernandomm avatar fivell avatar jackdanger avatar javierjulio avatar joelmoss avatar josevalim avatar ka8725 avatar maschwenk avatar rafaelfranca avatar rin avatar seanlinsley avatar sirupsen avatar taavo avatar tagliala avatar tb avatar timoschilling avatar tomascco avatar varyonic avatar vorontsovie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

inherited_resources's Issues

Inherited Resources still does not work with Bundler

Now Bundler does not trigger autoload and application can not find InheritedResources::Base.

There is a way to start:

Gemfile:

...
gem 'inherited_resources', :require_as => []
...

environment.rb:

Rails::Initializer.run do |config|
  ...
  config.gem 'inherited_resources'
  ...
end

Setting flash within success/failure block doesn't overwrite automatically set flash

This is probably the expected behavior, but it's less than ideal. When setting a flash within success/failure blocks, the flash is added to the flash that's automatically set by inherited_resources. I think a better behavior would be to only automatically add a flash if one was not explicitly set in the success/failure block. For example, in the following code I would expect one flash, but end up with two:

def update
update! do |success, failure|
success.html do
flash[:success] = 'Your account has been updated.'
redirect_to account_path
end
end
end

parent not available on new/create action

i have some nested resources, and i check resource authorization with cancan.
in my ability.rb i need to check authorization on the parents rescource, so i set it in current_ability

this works fine, but it seams that on new or create actions the parent is set in IR.

any idea?
thanks a lot,
marco

begin_of_association_chain : A small issue, but it's bugging me.

Shoot me down if I'm being pedantic, but this is Ruby!

I'm wondering if there's any reason for naming "begin_of_association_chain" as such ... it's not correct English, and I feel it sticks out in an otherwise very solid implementation.

I'd hazard that it should be 'beginning_of_association_chain" or "start_of_association_chain"

What do you think? Is this too anal?

Paul

Malfunction when using IR with acts_as_audited

Hello Jose!

I was trying to use IR together with acts_as_audited (http://wiki.github.com/collectiveidea/acts_as_audited/), but it doesn't seems to work. When trying to access any controller in my app, everything just freezes, I got not action being actually invoked. Killing the server process and removing the config.gem line for IR from my environment.rb seems to fix the problem.

Using:
inherited_resources 1.0.3
acts_as_audited 1.1.1
Rails 2.3.5
Ruby: ree-1.8.7-2010.01

Cheers!

acts as tree support (self association)

Hello,

I tried to use inherited resources with acts_as_tree without success. An example:

class Page < ActiveRecord::Base
  acts_as_tree
end

class PagesController < ApplicationController
  inherit_resources
  respond_to :html
  actions :all
  belongs_to :parent, :optional => true
end

map.resources :pages, :has_many => :pages

When I access http://localhost:3000/pages/3/pages the filter doesn't work.

I got the same behaviour of http://localhost:3000/pages/

You can verify that?

parent_url

Consider also adding child_url and sibling_url.

uninitialized constant Rails::Railtie using version 1.0 with Rails 2.3.5

Rails 2.3.5 application w/ "config.gem 'inherited_resources', :version => '1.0'" in environment.rb fails with the below error on 1.9.1 and 1.8.7 following a gem update today.

=> Rails 2.3.5 application starting on http://0.0.0.0:3000
/opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:440:in rescue in load_missing_constant': uninitialized constant Rails::Railtie (NameError) from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:436:inload_missing_constant'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in const_missing_with_dependencies' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/responders-0.5.0/lib/responders.rb:5:inmodule:Responders'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/responders-0.5.0/lib/responders.rb:1:in <top (required)>' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:inrequire'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in block in require' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:innew_constants_in'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in require' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/inherited_resources-1.0.0/lib/inherited_resources.rb:9:in<top (required)>'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in require' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:inblock in require'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in new_constants_in' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:inrequire'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rails-2.3.5/lib/rails/gem_dependency.rb:208:in load' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rails-2.3.5/lib/initializer.rb:307:inblock in load_gems'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rails-2.3.5/lib/initializer.rb:307:in each' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rails-2.3.5/lib/initializer.rb:307:inload_gems'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rails-2.3.5/lib/initializer.rb:164:in process' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rails-2.3.5/lib/initializer.rb:113:inrun'
from /Users/fuzz/Projects/web/config/environment.rb:13:in <top (required)>' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:inrequire'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in block in require' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:innew_constants_in'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in require' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rails-2.3.5/lib/commands/server.rb:84:in<top (required)>'
from script/server:3:in require' from script/server:3:in

'

weirdness with apache/passenger/rails 2.3.5 and IR 1.0.3

http://meatspacemarketing.com shows the error live, from my apache error log:

root@li49-36:/var/www/apps/production# tail -n 50 /var/log/apache2/error.log
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/abstract_server.rb:352:in __send__' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/abstract_server.rb:352:inmain_loop'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/abstract_server.rb:196:in start_synchronously' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/bin/passenger-spawn-server:61 /var/www/apps/production/msm/releases/20100218021704/config/initializers/searchlogic_geokit_formastic_compat.rb:52: warning: already initialized constant VALID_FIND_OPTIONS ** [NewRelic] New Relic RPM Agent 2.10.4 Initialized: pid = 13145 ** [NewRelic] Agent Log found in /var/www/apps/production/msm/releases/20100218021704/log/newrelic_agent.log *** Exception NoMethodError in PhusionPassenger::Railz::ApplicationSpawner (undefined method[]=' for nil:NilClass) (process 12763):
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/inherited_resources-1.0.3/lib/inherited_resources/class_methods.rb:241:in initialize_resources_class_accessors!' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/inherited_resources-1.0.3/lib/inherited_resources/class_methods.rb:261:insend'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/inherited_resources-1.0.3/lib/inherited_resources/class_methods.rb:261:in inherited' from /var/www/apps/production/msm/releases/20100218021704/app/controllers/events_controller.rb:1 from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:ingem_original_require'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in require' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:158:inrequire'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:265:in require_or_load' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:224:independ_on'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:136:in require_dependency' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:414:inload_application_classes'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:413:in each' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:413:inload_application_classes'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:411:in each' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:411:inload_application_classes'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:197:in process' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:insend'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in run' from /var/www/apps/production/msm/releases/20100218021704/config/environment.rb:9 from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:ingem_original_require'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in require' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/railz/application_spawner.rb:299:inpreload_application'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/railz/application_spawner.rb:248:in initialize_server' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/utils.rb:255:inreport_app_init_status'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/railz/application_spawner.rb:233:in initialize_server' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/abstract_server.rb:194:instart_synchronously'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/abstract_server.rb:163:in start' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/railz/application_spawner.rb:209:instart'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/spawn_manager.rb:262:in spawn_rails_application' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/abstract_server_collection.rb:126:inlookup_or_add'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/spawn_manager.rb:256:in spawn_rails_application' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/abstract_server_collection.rb:80:insynchronize'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/abstract_server_collection.rb:79:in synchronize' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/spawn_manager.rb:255:inspawn_rails_application'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/spawn_manager.rb:154:in spawn_application' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/spawn_manager.rb:287:inhandle_spawn_application'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/abstract_server.rb:352:in __send__' from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/abstract_server.rb:352:inmain_loop'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.9/bin/passenger-spawn-server:61
[ pid=12767 file=ext/apache2/Hooks.cpp:660 time=2010-02-17 23:51:23.678 ]:
Apache stopped forwarding the backend's response, even though the HTTP client did not close the connection. Is this an Apache bug?
root@li49-36:/var/www/apps/production#

Controller tests fail when stubbing models to be invalid

It seems my tests don't pass when I use Inherited Resources and stub a model to be invalid (although the application works fine).

I'm using Shoulda with Ryan Bates nifty scaffold generator, but I've also tried Test::Unit (both standard and 2.x). Here are examples I've tried:

test "should not create user" do
  User.any_instance.stubs(:valid?).returns(false)
  post :create
  assert_template 'new'
end

context "create action" do
  should "render new template when model is invalid" do
    User.any_instance.stubs(:valid?).returns(false)
    post :create
    assert_template 'new'
  end
end

Using the standard controller code, it works fine, but when I inherit from Inherited Resources:

class UsersController < InheritedResources::Base
end

The test fails:
1) Failure:
test: invalid create action should render template :new. (UsersControllerTest)
[shoulda (2.10.3) lib/shoulda/action_controller/macros.rb:164:in __bind_1264668968_695329' shoulda (2.10.3) lib/shoulda/context.rb:362:incall'
shoulda (2.10.3) lib/shoulda/context.rb:362:in `test: invalid create action should render template :new. ']:
expecting <"new"> but rendering with <"">

It also fails when testing responses:

1) Failure:
test: invalid create action should respond with success. (UsersControllerTest)
response to be a 200, but was 302

I've tried to mofidy my code to look like this:
class UsersController < InheritedResources::Base
def create
create! do |success, failure|
failure.html do
render :action => 'new'
end
end
end
end

Debugging the test shows the render method is never called. If I add a success block, the success block is called, but the failure block isn't.

If I add a validation rule to User model (for example, validates presence of name) and remove the stub in my tests, the test pass. Note that if I add the validation rule but still do the stub, it still fails. So I guess it has something to do with the stub.

Is there anything I'm doing wrong? I've looked for information about it, but I've only found a bug when using RSpec (which looks pretty similar).

BTW: I've shown the examples with the "create" action, but the same happens with "update".

Thanks!

Edit: Forgot to say, I'm using Rails 2.3.5, Inherited Resources 1.0.2, mocha 0.9.8 and shoulda 2.10.3

Rails 3: No routes matches

Rails 3 beta, Ruby 1.87

class People < AplicationController
inherited_resources
end

routes.rb
...
resources :people
...

view

link_to 'People', people_path

Error: No routes matches /people

Destroy action

When I add actions as follow:

actions :index, :show, :new, :edit, :create, :update
and try to delete it's delete the field in database. So, it's a bug! I don't want to delete anything.

But, when I add actions like:

actions :all, :except => [ :destroy ]
and try to delete it doesn't delete. So, it's correct because I don't want to create destroy action.

Thanks,

Shortcut syntax does not work with rspec

The syntax:

def create
  create!{ another_url }
end

Does not work with Rspec controller specs if integrate views is false because that template is executed just if a template is not found. Since rspec hacks all templates to be found on integrate_views equals to true, the code is never executed. The solution is to use success and failure blocks:

def create
  create! do |success, failure| 
    success.html { another_url }
  end
end

No flash messages

It seems that flash messages are gone now that I've upgraded to 1.0.3 version. It is not related to keys of flash messages, because when I try to inspect flash I get empty hash. When I set flash message directly it works.

protected method for finders

I've got a controller like this:

class BrandsController < InheritedResources::Base
  before_filter :authenticate, :ensure_brand_manager

  actions    :new, :create
  belongs_to :sponsor

  protected

  def ensure_brand_manager
    sponsor = Sponsor.find(params[:sponsor_id])
    unless sponsor.brand_managers.include?(current_user)
      flash[:failure] = "Permission denied"
      redirect_to root_path
    end
  end
end

The line I'd like to push off to Inherited Resources is:

sponsor = Sponsor.find(params[:sponsor_id])

On this controller, I'd like there to be protected methods available to me that do:

sponsor = Sponsor.find(params[:sponsor_id])
brand = Brand.find(params[:id])

and/or:

parent = Sponsor.find(params[:sponsor_id])
resource = Brand.find(params[:id])

Making these available in all Inherited Resources controllers would save me a line in about all of my controllers while maintaining readability.

What do you think?

Overriding location path with block does not work (inherited_resources 1.0.1)

inherited_resources (1.0.1)

This example in the readme file does not work (on create action at least)

class ProjectsController < InheritedResources::Base
  def destroy
    destroy!{ root_url }
  end
end

also I found some references to an option argument with name :location, can you provide any examples on how to use it? i'm unable to make it work neither

Rails 3 problem with class_inheritable_reader

Hi!
I try use rails

git 'git://github.com/rails/rails.git'
gem 'activesupport', '~> 3.0.0.beta1', :require => 'active_support'

git 'git://github.com/josevalim/inherited_resources.git'
gem 'inherited_resources', '~> 1.1.0'

and catch trouble
class_inheritable_hash :resources_configuration

behaviour is fail in
module InheritedResources
module ClassMethods

self.resources_configuration ||= {}
is fail
self.resources_configuration.nil? == true
but resources_configuration ||= {}
resources_configuration.nil? == false
is work success.

Can any one explain this?

Feature request: edit_parent_url

It would be nice if in addition to "parent_url", there was "edit_parent_url". Additions/updates to children may often redirect to the edit page of the parent rather than the show. (at least in my apps, but maybe I'm doing it wrong)

Best Regards,
David Baldwin

Flashes appear twice

Since updating inherited_resources from 0.9.3 to 0.9.4, all actions are getting two flashes -- one with :notice and one with :success. Issue is reproducible in base Rails app.

Calling inherit_resources in a controller doesn't initialize responders

If I do

class PostsController < ApplicationController
  inherit_resources
end

intead of subclassing InheritedResources::Base responders don't seem to work (e.g. flash messages are not set). I'm not really familiar with the internals of IR/Responders, but after a quick look, it appears that this line http://github.com/josevalim/inherited_resources/blob/master/lib/inherited_resources/base.rb#L42 makes the difference. If I add it to my controller like this:

class PostsController < ApplicationController
  inherit_resources
  self.responder = InheritedResources::Responder
end

flash messages at least start working.

Hope it makes sense. Thanks!

Firefox 3.5

Hi,

I was trying out inherited_resources today and got it working really well with a test controller in an admin/ namespace ... The controller worked great in Safari, but not so much in Firefox (3.5) ... claiming that the template was not present...

... appending ".html" to the URL makes it work, so I suspect that there's no defaulting to .html in the plugin, perhaps a reliance on the Accept header?

Paul

Failing tests - gem loading issue(s)

$ rake test --trace                                                                                                                                                           (09-04 03:44)
(in /Users/Jonas/Development/examples/inherited_resources)
** Invoke test (first_time)
** Execute test
/opt/local/bin/ruby -I"lib" "/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/aliases_test.rb" "test/association_chain_test.rb" "test/base_test.rb" "test/belongs_to_test.rb" "test/class_methods_test.rb" "test/customized_belongs_to_test.rb" "test/defaults_test.rb" "test/flash_test.rb" "test/has_scope_test.rb" "test/nested_belongs_to_test.rb" "test/optional_belongs_to_test.rb" "test/polymorphic_test.rb" "test/redirect_to_test.rb" "test/respond_to_test.rb" "test/singleton_test.rb" "test/url_helpers_test.rb" 
DEPRECATION WARNING: has_scope :key is deprecated, use :as instead. (called from has_scope at /Users/Jonas/Development/examples/inherited_resources/lib/inherited_resources/class_methods.rb:131)
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:105:in `const_missing': uninitialized constant Test::Unit::TestResult::TestResultFailureSupport (NameError)
    from /opt/local/lib/ruby/gems/1.8/gems/test-unit-2.0.2/lib/test/unit/testresult.rb:28
    from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'

While searching for info on this I found:

You can't use Test::Unit 2.0 with old Test::Unit.
Call 'gem "test-unit"' before 'require "test/unit".

should not assume a parent if belongs_to is specified

I have an invitations controller that I would like to use both nested as well as unnested. The controller is set up like this:

class InvitationsController < ApplicationController
inherit_resources
belongs_to :league
end

and I am accessing the controller both from /leagues/{id}/invitations and /invitations

Since inherited_resources always assumes a parent if belongs_to is defined, it throws an error trying to find the parent league when I access the unnested route. Instead, it should check for the presence of the parent_id first and only load the parent if it exists.

Not compatible with MongoMapper (Validations plugin)

Hello.

I'm trying to use this great plugin with MongoMapper. After destroy action InheritedResources calls 'has_errors' method after destroying and freezing the record. But have a look at this line:

http://github.com/jnunemaker/validatable/blob/master/lib/validatable/errors.rb#L59

Validations is used by MongoMapper... So plugin is trying to set instance variable when the instance is already frozen.

I don't think it is a bug of IR, but the author of Validations and MongoMapper doesnt what to fix this issue.

Best regards,
Ivan Ukhov.

Controller with shared views, when using STI

If I use STI in my ActiveRecord models, and I have a controller for each model, and my controllers inherit from InheritedResources::Base, I end up having a lot of duplication of code in the views. In a normal controller, I would use "render 'shared/blah'" and use shared view templates in app/views/shared.

How can I do this with the Inherited Resources plugin? My apologies if this is a silly question, I'm quite new at this.

Swallows too many exceptions

There are some problem areas where exceptions are being silently discarded only to lead to errors further on that are hard to track down.

E.g. class_methods.rb:306 gets the resource class but rescues and returns nil if my model definition has an error, leading to an exception in the IR code later on when it calls find on nil.

There are also "rescue nil" lines in the controller methods that have caused me problems.

Will fork and try to patch in Jan, but if there are any particular reasons for these or no one else experiences this I'd be interested in hearing about it.

Thanks!

Getting 'superclass mismatch for class Responder'

Hi!
I am using http://code.google.com/p/mail-queue/ for asynchronous mail processing, i.e. every now and then I run 'ruby /script/runner 'MailQueue.process' -e production' to send all queued mails.

I am not sure if mail_queue is the source of the problem but when running the above, I get the following error:

/bla/bla/bla/vendor/plugins/inherited_resources/lib/inherited_resources/responder.rb:2: superclass mismatch for class Responder (TypeError)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:158:in require' from /bla/bla/bla/vendor/plugins/inherited_resources/lib/inherited_resources/base.rb:2 from /bla/bla/bla/vendor/plugins/inherited_resources/lib/inherited_resources.rb:39:ininherit_resources'
from /bla/bla/bla/app/controllers/activities_controller.rb:2
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:158:in require' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:265:inrequire_or_load'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:224:in depend_on' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:136:inrequire_dependency'
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:414:in load_application_classes' from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:413:ineach'
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:413:in load_application_classes' from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:411:ineach'
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:411:in load_application_classes' from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:197:inprocess'
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in send' from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:inrun'
from /home/users/register/releases/20100106215523/config/environment.rb:9
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/runner.rb:39
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from ./script/runner:3

where the ActivitiesController looks something like:

class ActivitiesController < ApplicationController
inherit_resources
actions :all
etc...

Any hints on this one?

Cheers,
Anders

polymorphic_symbols is undefined

When the exception is raised because no polymorphic association is found, the exception text contains #{polymorphic_symbols.inspect}. It throws another error because polymorphic_symbols doesn't exist.

if key.nil?
raise ScriptError, "Could not find param for polymorphic association.
The request params keys are #{params.keys.inspect}
and the polymorphic associations are
#{polymorphic_symbols.inspect}." unless polymorphic_config[:optional]

          nil

Ruby 1.9 mime responder issues (together with AuthHelpers)

TypeError ({:with=>#} is not a symbol):
  /Users/jonas/.ruby_versions/ruby-1.9.1-p129/lib/ruby/gems/1.9.1/gems/inherited_resources-0.9.1/lib/inherited_resources/legacy/respond_to.rb:100:in `block in retrieve_response_from_mimes'
  /Users/jonas/.ruby_versions/ruby-1.9.1-p129/lib/ruby/gems/1.9.1/gems/inherited_resources-0.9.1/lib/inherited_resources/legacy/respond_to.rb:100:in `each'
  /Users/jonas/.ruby_versions/ruby-1.9.1-p129/lib/ruby/gems/1.9.1/gems/inherited_resources-0.9.1/lib/inherited_resources/legacy/respond_to.rb:100:in `retrieve_response_from_mimes'
  /Users/jonas/.ruby_versions/ruby-1.9.1-p129/lib/ruby/gems/1.9.1/gems/inherited_resources-0.9.1/lib/inherited_resources/legacy/respond_to.rb:56:in `respond_to'
  ...

Note: I run a slightly modified version of InheritedResources, but only touched rake/tests so far.

Cancel button (with code)

Hi,

This thread: http://groups.google.com.au/group/formtastic/browse_thread/thread/9bb5d808d2a9adbf talk about cancel button.

I write a method that I'm using into a initializer file (is a monkey patch in really) but do the proposed feature.

I know that's obstrutive solution using window.history.back() or window.location = url; but the unobstrutive solution aren't greater IMHO (create a inline form reseting all css properties of this form elements using action to proposed url and get method).

This sounds to a bad workaround.

The dev will be advised about obstrutivity and I guess that's not a problem considering dev can make the unobstrutive solution by yourself if really needed.

You will use the cancel_button method:

- form.inputs do
  = form.submit_button
  = form.cancel_button
  = form.cancel_button admin_pages_path
  = form.cancel_button admin_pages_path, { :button_html => { :class => 'pretty_button' } }
  = form.cancel_button admin_pages_path, 'Cancel updates'
  = form.cancel_button admin_pages_path, 'Cancel updates', { :button_html => { :class => 'pretty_button' } }

The default url is :back, this means, window.history.back() and the default button text is I18n.t('formtastic.cancel', :default => 'Cancel').

If you specify a url, this will be "window.location = #{url.to_json}"

I guess this solve 99.9% of cancel button cases.

See the code: http://paste.pocoo.org/show/145765/

Problem with Clearance Integration

In my app, I'm using Clearance as my Auth purpose. I'm trying to use IHR.
For the model association,

#user.rb
has_many :masterpieces, :dependent => :destroy
#masterpiece.rb
belongs_to :user

Masterpiece controller:

class MasterpiecesController < ApplicationController
  before_filter :authenticate, :except => [:show, :index]
  def index
    @masterpieces = Masterpiece.all
  end
  def new
    @masterpiece = current_user.masterpieces.build
  end
  def create
    @masterpiece = current_user.masterpieces.build(params[:masterpiece])
    respond_to do |format|
      if @masterpiece.save
        flash[:notice] = 'Masterpiece was successfully created.'
        format.html { redirect_to(@masterpiece) }
        format.xml  { render :xml => @masterpiece, :status => :created, :location => @masterpiece }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @masterpiece.errors, :status => :unprocessable_entity }
      end
    end

  end
  def show
    @masterpiece = current_user.masterpieces.find(params[:id])
  end
end

Now when I replace this controller with this version using IHR:

class MasterpiecesController < InheritedResources::Base
  before_filter :authenticate, :except => [:show, :index]

  respond_to :html, :js
  belongs_to :user

  protected

  def begin_of_association_chain
    current_user
  end
end

And I go to /masterpieces/new
I get the following error:

 NoMethodError in MasterpiecesController#new

undefined method `users' for #

passing serialization options

Is there any way to pass options to to_xml? I have many situations where I need to pass things like :root, :include, or :methods and the only way I have figured out is to override the whole action. Is there another way?

for example, in my app I have a base controller which defines a to_xml_parameters method which I always want to pass to to_xml. It seems redundant to put that in all controllers.

Thanks.

Running into bug using inherited_resources with DataMapper

I am trying out inherited_resources with DataMapper. I found that mimes_for_respond_to resolves to nil. Based on my debugging, I think this is because inherited_resources assumes developers are using the class inheritable attribute methods from ActiveSupport, while DataMapper provides a subset of those methods with a different implementation using the Extlib gem. This results in data being stored using ActiveSupport's write_inheritable_attribute method, but that data can't be accessed because inherited_resources ends up using Extlib's class_inheritable_reader, resulting in mimes_for_respond_to resolving to nil. Not sure how to do a work-around gracefully without messing up other libs that depend on DataMapper's Extlib and ActiveSupport.

Gemcutter support

Seeing as how Github no longer supports building gems, can you add this gem to gemcutter? I am currently unable to find it there as I migrate all my old github gems to their gemcutter counterparts.

callback before_destroy does not work

hi,
since version 1.0.0 using of callback before_destroy does not work correctly with inherited_resources.

example:
git clone git://github.com/akitaonrails/ryanb-15min-blog.git
git checkout remotes/origin/inherited_resources

config/environment.rb
config.gem "inherited_resources", :version => "1.0.0"

app/models/post.rb
class Post < ActiveRecord::Base
def before_destroy
false
end
end

When I start scrip/server and I try to destroy some of created posts, Post is not destroyed, but I get notice Post was successfully destroyed..

Resources not honoring after_initialize

I have a resource that has some accessors created within an after_initialize method...

class Project < ActiveRecord::Base
  def after_initialize
    # create method...
  end
  ...

In the controller I have the "new" action automatically created with inherited resources. However, the resource is nil when it hits the "after_initialize". However, if I explicitly add the new method, everyone works fine...

 def new
   @project = end_of_association_chain.new
 end

Shouldn't the resource being automatically created with inherited resources also be using end_of_association_chain.new?

BTW - I do have :new listed as an action in the controller, and inherited resources works splendidly almost everywhere

Best regards,
David Baldwin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.