Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if a resource is save and respond_to #2

Closed
Awea opened this issue Sep 20, 2012 · 3 comments
Closed

Check if a resource is save and respond_to #2

Awea opened this issue Sep 20, 2012 · 3 comments

Comments

@Awea
Copy link

Awea commented Sep 20, 2012

Hi @hopsoft, I really like your gem it make my controller really skinny but :

if I have a resource scoped in another

example

resources :projects do
    resources :depot_ids, :except => [:index]
[...]

I need to change respond_to and some other stuff to make it work properly but if I use the respond_to callback I can't easily check if a resource was save or not and do my redirect or my render with erros.

if I use namespace

example

namespace :admin do 
  resources :contents 
end

namespace :front, :path => '' do
  resources :contents, :only => [:index]
end

I got the same problem :)

Solution

May be can change local var success to instance var @success ? If you agree I'll did it -)

@hopsoft
Copy link
Owner

hopsoft commented Sep 20, 2012

I like where you are going with this. I want to setup a test case so I can better feel your pain and then come out of that with a solution, but I like your initial idea of using an instance variable.

@Awea
Copy link
Author

Awea commented Sep 24, 2012

I've made my change

@hopsoft
Copy link
Owner

hopsoft commented Oct 6, 2012

Closing this issue since there is a workable solution without requiring a change. https://github.com/Awea/coast/commit/0ced2e3301bfd983ba15232538374cfd831daece

respond_to :create do
  if @project.errors.empty?
    redirect_to [@project, @resource], notice: 'Resource was successfully created.'
  else
    @project = Project.find(params[:project_id])
    render action: "new"
  end
end

@hopsoft hopsoft closed this as completed Oct 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants