[Instantrails-users] One Last Question for me..

Curt Hibbs curt.hibbs at gmail.com
Thu Jan 19 10:32:27 EST 2006


On 1/19/06, MaxSteel <maxsteel at gmail.com> wrote:
>
> And then I should be ready to roll with my project..  I have some fine
> tuning of the looks to do after, but funtionality first!
>
> This is probably a rails question.. but I'm not sure where to sign up
> for the rails questions email group?  (I guess I turned this into a 2
> question email).


You can find it here:

   http://rubyonrails.org/community

I'll ask here and then if someone will send me the url of where I go
> to sign up for the rails type questions, that'd be great!
>
> now let's see if i can explain it:
>
> (once again using the recipe example provided)
>
> by default after you edit a category name, it "redirects" to a showing
> of the new category name (by id)  eg:  /category/show/6
>
> because I've feverishly edited the show.rhtml (for a different
> purpose) I get nasty errors after updating the category name.
>
> What is the easiest way to change that so it redirects back to say
> /category/list ?
>
> i know that:
> def show
> redirect_to :action => 'list'
> end
>
> will work, but that will kill my current "show" (for category controller):
>       @categories = Category.find_all
>       @recipes = Recipe.find_all
>       @c = @params['c']
>       @r = @params['r']
>       @recipe = Recipe.find(@params["r"])
>
> is there some way to accomplish this with an if/else statement?
>
> I've googled high and low.. I can't seem to find much documentation on
> controller syntax, so it's easily errored (anyone have a good site for
> this? ..please?)
>
> my attempts has lead me to such:
>
> def show
>    if
>       redirect_to :action => 'list'
>    else
>       @categories = Category.find_all
>       @recipes = Recipe.find_all
>       @c = @params['c']
>       @r = @params['r']
>       @recipe = Recipe.find(@params["r"])
>    end
> end
>
> I just don't know what to put after the if to say if (url) "
> /category/show/id# " then redirect_to :action => 'list'
> else just pass the params.
>
> If anyone can help much appreciated..
>
> (hope that made sense)
>
> If I can get it to work I'm willing to pass on my recipe 2.0, if you
> will, to anyone who cares to take a peek!
>
> Thanks again!
> Ryan


You're main problem is that you want to modify the scafolding code, but
since you followed the tutorial, you are using dynamic which creates the
behavior dynamically at runtime, so there isn't any code to modify. What you
need to do is to actually generate the scaffold code. That way it will
phsyically exist in files that you can edit and modify.

Make a backup of your files before you do this because generating the
scaffold code will overwrite stuff. Then open a command window, move to the
cook directory, and run the command:

  ruby script\generate scaffold category category

Say yes when for each file it asks to overwrite. Now when you edit
catergory_controller.rb you will see all of the scaffolding code and you can
change that redirect to show to go somewhere else.

Curt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/instantrails-users/attachments/20060119/86ee50ce/attachment.htm


More information about the Instantrails-users mailing list