Giter VIP home page Giter VIP logo

inherited_resources's Introduction

Notice

Inherited Resources is no longer actively maintained by the original author and has been transferred to the ActiveAdmin organization for maintenance. New feature requests are not encouraged.

If you are not already using Inherited Resources we suggest instead using Rails' respond_with feature alongside the responders gem.

Inherited Resources

Version         Github Actions  Tidelift

Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important. It makes your controllers more powerful and cleaner at the same time.

In addition to making your controllers follow a pattern, it helps you to write better code by following fat models and skinny controllers convention. There are two screencasts available besides this README:

Installation

You can let bundler install Inherited Resources by adding this line to your application's Gemfile:

gem 'inherited_resources'

And then execute:

$ bundle install

Or install it yourself with:

$ gem install inherited_resources

HasScope

Since Inherited Resources 1.0, has_scope is not part of its core anymore but a gem dependency. Be sure to check the documentation to see how you can use it:

And it can be installed as:

$ gem install has_scope

Responders

Since Inherited Resources 1.0, responders are not part of its core anymore, but is set as Inherited Resources dependency and it's used by default by InheritedResources controllers. Be sure to check the documentation to see how it will change your application:

And it can be installed with:

$ gem install responders

Using responders will set the flash message to :notice and :alert. You can change that through the following configuration value:

InheritedResources.flash_keys = [ :success, :failure ]

Notice the CollectionResponder won't work with InheritedResources, as InheritedResources hardcodes the redirect path based on the current scope (like belongs to, polymorphic associations, etc).

Basic Usage

To use Inherited Resources you just have to inherit (duh) it:

class ProjectsController < InheritedResources::Base
end

And all actions are defined and working, check it! Your projects collection (in the index action) is still available in the instance variable @projects and your project resource (all other actions) is available as @project.

The next step is to define which mime types this controller provides:

class ProjectsController < InheritedResources::Base
  respond_to :html, :xml, :json
end

You can also specify them per action:

class ProjectsController < InheritedResources::Base
  respond_to :html, :xml, :json
  respond_to :js, :only => :create
  respond_to :iphone, :except => [ :edit, :update ]
end

For each request, it first checks if the "controller/action.format" file is available (for example "projects/create.xml") and if it's not, it checks if the resource respond to :to_format (in this case, :to_xml). Otherwise returns 404.

Another option is to specify which actions the controller will inherit from the InheritedResources::Base:

class ProjectsController < InheritedResources::Base
  actions :index, :show, :new, :create
end

Or:

class ProjectsController < InheritedResources::Base
  actions :all, :except => [ :edit, :update, :destroy ]
end

In your views, you will get the following helpers:

resource        #=> @project
collection      #=> @projects
resource_class  #=> Project

As you might expect, collection (@projects instance variable) is only available on index actions.

If for some reason you cannot inherit from InheritedResources::Base, you can call inherit_resources in your controller class scope:

class AccountsController < ApplicationController
  inherit_resources
end

One reason to use the inherit_resources macro would be to ensure that your controller never responds with the html mime-type. InheritedResources::Base already responds to :html, and the respond_to macro is strictly additive. Therefore, if you want to create a controller that, for example, responds ONLY via :js, you will have to write it this way:

class AccountsController < ApplicationController
  respond_to :js
  inherit_resources
end

Overwriting defaults

Whenever you inherit from InheritedResources, several defaults are assumed. For example you can have an AccountsController for account management while the resource is a User:

class AccountsController < InheritedResources::Base
  defaults :resource_class => User, :collection_name => 'users', :instance_name => 'user'
end

In the case above, in your views you will have @users and @user variables, but the routes used will still be accounts_url and account_url. If you plan also to change the routes, you can use :route_collection_name and :route_instance_name.

Namespaced controllers work out of the box, but if you need to specify a different route prefix you can do the following:

class Administrators::PeopleController < InheritedResources::Base
  defaults :route_prefix => :admin
end

Then your named routes will be: admin_people_url, admin_person_url instead of administrators_people_url and administrators_person_url.

If you want to customize how resources are retrieved you can overwrite collection and resource methods. The first is called on index action and the second on all other actions. Let's suppose you want to add pagination to your projects collection:

class ProjectsController < InheritedResources::Base
  protected
    def collection
      get_collection_ivar || set_collection_ivar(end_of_association_chain.paginate(:page => params[:page]))
    end
end

The end_of_association_chain returns your resource after nesting all associations and scopes (more about this below).

InheritedResources also introduces another method called begin_of_association_chain. It's mostly used when you want to create resources based on the @current_user and you have urls like "account/projects". In such cases you have to do @current_user.projects.find or @current_user.projects.build in your actions.

You can deal with it just by doing:

class ProjectsController < InheritedResources::Base
  protected
    def begin_of_association_chain
      @current_user
    end
end

Overwriting actions

Let's suppose that after destroying a project you want to redirect to your root url instead of redirecting to projects url. You just have to do:

class ProjectsController < InheritedResources::Base
  def destroy
    super do |format|
      format.html { redirect_to root_url }
    end
  end
end

You are opening your action and giving the parent action a new behavior. On the other hand, I have to agree that calling super is not very readable. That's why all methods have aliases. So this is equivalent:

class ProjectsController < InheritedResources::Base
  def destroy
    destroy! do |format|
      format.html { redirect_to root_url }
    end
  end
end

Since most of the time when you change a create, update or destroy action you do so because you want to change its redirect url, a shortcut is provided. So you can do:

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

If you simply want to change the flash message for a particular action, you can pass the message to the parent action using the keys :notice and :alert (as you would with flash):

class ProjectsController < InheritedResources::Base
  def create
    create!(:notice => "Dude! Nice job creating that project.")
  end
end

You can still pass the block to change the redirect, as mentioned above:

class ProjectsController < InheritedResources::Base
  def create
    create!(:notice => "Dude! Nice job creating that project.") { root_url }
  end
end

Now let's suppose that before create a project you have to do something special but you don't want to create a before filter for it:

class ProjectsController < InheritedResources::Base
  def create
    @project = Project.new(params[:project])
    @project.something_special!
    create!
  end
end

Yes, it's that simple! The nice part is since you already set the instance variable @project, it will not build a project again.

Same goes for updating the project:

class ProjectsController < InheritedResources::Base
  def update
    @project = Project.find(params[:id])
    @project.something_special!
    update!
  end
end

Before we finish this topic, we should talk about one more thing: "success/failure blocks". Let's suppose that when we update our project, in case of failure, we want to redirect to the project url instead of re-rendering the edit template.

Our first attempt to do this would be:

class ProjectsController < InheritedResources::Base
  def update
    update! do |format|
      unless @project.errors.empty? # failure
        format.html { redirect_to project_url(@project) }
      end
    end
  end
end

Looks too verbose, right? We can actually do:

class ProjectsController < InheritedResources::Base
  def update
    update! do |success, failure|
      failure.html { redirect_to project_url(@project) }
    end
  end
end

Much better! So explaining everything: when you give a block which expects one argument it will be executed in both scenarios: success and failure. But if you give a block that expects two arguments, the first will be executed only in success scenarios and the second in failure scenarios. You keep everything clean and organized inside the same action.

Smart redirects

Although the syntax above is a nice shortcut, you won't need to do it frequently because (since version 1.2) Inherited Resources has smart redirects. Redirects in actions calculates depending on the existent controller methods.

Redirects in create and update actions calculates in the following order: resource_url, collection_url, parent_url (which we are going to see later), and root_url. Redirect in destroy action calculate in following order collection_url, parent_url, root_url.

Example:

class ButtonsController < InheritedResources::Base
  belongs_to :window
  actions :all, :except => [:show, :index]
end

This controller redirect to parent window after all CUD actions.

Success and failure scenarios on destroy

The destroy action can also fail, this usually happens when you have a before_destroy callback in your model which returns false. However, in order to tell InheritedResources that it really failed, you need to add errors to your model. So your before_destroy callback on the model should be something like this:

def before_destroy
  if cant_be_destroyed?
    errors.add(:base, "not allowed")
    false
  end
end

Belongs to

Finally, our Projects are going to get some Tasks. Then you create a TasksController and do:

class TasksController < InheritedResources::Base
  belongs_to :project
end

belongs_to accepts several options to be able to configure the association. For example, if you want urls like "/projects/:project_title/tasks", you can customize how InheritedResources find your projects:

class TasksController < InheritedResources::Base
  belongs_to :project, :finder => :find_by_title!, :param => :project_title
end

It also accepts :route_name, :parent_class and :instance_name as options. Check the lib/inherited_resources/class_methods.rb for more.

Nested belongs to

Now, our Tasks get some Comments and you need to nest even deeper. Good practices says that you should never nest more than two resources, but sometimes you have to for security reasons. So this is an example of how you can do it:

class CommentsController < InheritedResources::Base
  nested_belongs_to :project, :task
end

If you need to configure any of these belongs to, you can nest them using blocks:

class CommentsController < InheritedResources::Base
  belongs_to :project, :finder => :find_by_title!, :param => :project_title do
    belongs_to :task
  end
end

Warning: calling several belongs_to is the same as nesting them:

class CommentsController < InheritedResources::Base
  belongs_to :project
  belongs_to :task
end

In other words, the code above is the same as calling nested_belongs_to.

Polymorphic belongs to

We can go even further. Let's suppose our Projects can now have Files, Messages and Tasks, and they are all commentable. In this case, the best solution is to use polymorphism:

class CommentsController < InheritedResources::Base
  belongs_to :task, :file, :message, :polymorphic => true
  # polymorphic_belongs_to :task, :file, :message
end

You can even use it with nested resources:

class CommentsController < InheritedResources::Base
  belongs_to :project do
    belongs_to :task, :file, :message, :polymorphic => true
  end
end

The url in such cases can be:

/project/1/task/13/comments
/project/1/file/11/comments
/project/1/message/9/comments

When using polymorphic associations, you get some free helpers:

parent?         #=> true
parent_type     #=> :task
parent_class    #=> Task
parent          #=> @task

Right now, Inherited Resources is limited and does not allow you to have two polymorphic associations nested.

Optional belongs to

Later you decide to create a view to show all comments, independent if they belong to a task, file or message. You can reuse your polymorphic controller just doing:

class CommentsController < InheritedResources::Base
  belongs_to :task, :file, :message, :optional => true
  # optional_belongs_to :task, :file, :message
end

This will handle all those urls properly:

/comment/1
/tasks/2/comment/5
/files/10/comment/3
/messages/13/comment/11

This is treated as a special type of polymorphic associations, thus all helpers are available. As you expect, when no parent is found, the helpers return:

parent?         #=> false
parent_type     #=> nil
parent_class    #=> nil
parent          #=> nil

Singletons

Now we are going to add manager to projects. We say that Manager is a singleton resource because a Project has just one manager. You should declare it as has_one (or resource) in your routes.

To declare an resource of current controller as singleton, you just have to give the :singleton option in defaults.

class ManagersController < InheritedResources::Base
  defaults :singleton => true
  belongs_to :project
  # singleton_belongs_to :project
end

So now you can use urls like "/projects/1/manager".

In the case of nested resources (when some of the can be singletons) you can declare it separately

class WorkersController < InheritedResources::Base
  #defaults :singleton => true #if you have only single worker
  belongs_to :project
  belongs_to :manager, :singleton => true
end

This is correspond urls like "/projects/1/manager/workers/1".

It will deal with everything again and hide the action :index from you.

Namespaced Controllers

Namespaced controllers works out the box.

class Forum::PostsController < InheritedResources::Base
end

Inherited Resources prioritizes the default resource class for the namespaced controller in this order:

Forum::Post
ForumPost
Post

URL Helpers

When you use InheritedResources it creates some URL helpers. And they handle everything for you. :)

# /posts/1/comments
resource_url               # => /posts/1/comments/#{@comment.to_param}
resource_url(comment)      # => /posts/1/comments/#{comment.to_param}
new_resource_url           # => /posts/1/comments/new
edit_resource_url          # => /posts/1/comments/#{@comment.to_param}/edit
edit_resource_url(comment) # => /posts/1/comments/#{comment.to_param}/edit
collection_url             # => /posts/1/comments
parent_url                 # => /posts/1

# /projects/1/tasks
resource_url               # => /projects/1/tasks/#{@task.to_param}
resource_url(task)         # => /projects/1/tasks/#{task.to_param}
new_resource_url           # => /projects/1/tasks/new
edit_resource_url          # => /projects/1/tasks/#{@task.to_param}/edit
edit_resource_url(task)    # => /projects/1/tasks/#{task.to_param}/edit
collection_url             # => /projects/1/tasks
parent_url                 # => /projects/1

# /users
resource_url               # => /users/#{@user.to_param}
resource_url(user)         # => /users/#{user.to_param}
new_resource_url           # => /users/new
edit_resource_url          # => /users/#{@user.to_param}/edit
edit_resource_url(user)    # => /users/#{user.to_param}/edit
collection_url             # => /users
parent_url                 # => /

Those urls helpers also accepts a hash as options, just as in named routes.

# /projects/1/tasks
collection_url(:page => 1, :limit => 10) #=> /projects/1/tasks?page=1&limit=10

In polymorphic cases, you can also give the parent as parameter to collection_url.

Another nice thing is that those urls are not guessed during runtime. They are all created when your application is loaded (except for polymorphic associations, that relies on Rails' polymorphic_url).

Custom actions

Since version 1.2, Inherited Resources allows you to define custom actions in controller:

class ButtonsController < InheritedResources::Base
  custom_actions :resource => :delete, :collection => :search
end

This code creates delete and search actions in controller (they behaves like show and index actions accordingly). Also, it will produce delete_resource_{path,url} and search_resources_{path,url} url helpers.

What about views?

Sometimes just DRYing up the controllers is not enough. If you need to DRY up your views, check this Wiki page:

https://github.com/activeadmin/inherited_resources/wiki/Views-Inheritance

Notice that Rails 3.1 ships with view inheritance built-in.

Some DSL

For those DSL lovers, InheritedResources won't leave you alone. You can overwrite your success/failure blocks straight from your class binding. For it, you just need to add a DSL module to your application controller:

class ApplicationController < ActionController::Base
  include InheritedResources::DSL
end

And then you can rewrite the last example as:

class ProjectsController < InheritedResources::Base
  update! do |success, failure|
    failure.html { redirect_to project_url(@project) }
  end
end

Strong Parameters

If your controller defines a method named permitted_params, InheritedResources will call it where it would normally call params. This allows for easy integration with the strong_parameters gem:

def permitted_params
  params.permit(:widget => [:permitted_field, :other_permitted_field])
end

Remember that if your field is sent by client to server as an array, you have to write :permitted_field => [], not just :permitted_field.

Note that this doesn't work if you use strong_parameters' require method instead of permit, because whereas permit returns the entire sanitized parameter hash, require returns only the sanitized params below the parameter you required.

If you need params.require you can do it like this:

def permitted_params
  {:widget => params.fetch(:widget, {}).permit(:permitted_field, :other_permitted_field)}
end

Or better yet just override #build_resource_params directly:

def build_resource_params
  [params.fetch(:widget, {}).permit(:permitted_field, :other_permitted_field)]
end

Instead you can stick to a standard Rails 4 notation (as rails scaffold generates) and write:

def widget_params
  params.require(:widget).permit(:permitted_field, :other_permitted_field)
end

In such case you should remove #permitted_params method because it has greater priority.

Funding

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.

Bugs and Feedback

If you discover any bugs, please describe it in the issues tracker, including Rails and InheritedResources versions.

Questions are better handled on StackOverflow.

MIT License. Copyright (c) 2009-2017 Josรฉ Valim.

Security contact information

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

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

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

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.

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!

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 #

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

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

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

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!

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.

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

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

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.

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.

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#

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?

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.

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

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

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!

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?

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.

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".

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.

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.

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.

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

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..

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

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

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/

parent_url

Consider also adding child_url and sibling_url.

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

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?

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,

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.