Calling to a specfic controler

hi

i have created a rhtml file name as new.rhtml and in thir i have created
the form as follows

<% form_for :form_file, :url => { :action => “create” }, :html => {
:multipart => true } do |g| %>

<%= g.file_field :upload_file %>

<%= submit_tag :Up_load_now %>

<%= g.hidden_field :condition_file_type, :value => "IMAGE" -%> <% end %>

when the cubmit button is clicked it should go the a new controller
called fileuploader which has method name “create”

i do not know how to achieve this task…

On 15 Nov 2007, at 11:25, Nadeesha M. wrote:

<% end %>

when the cubmit button is clicked it should go the a new controller
called fileuploader which has method name “create”

if the create action isn’t on the same controller as the create
action, you need to specify it, ie
:url => { :action => “create”, :controller =>
‘some_other_controller’ }

Fred

Frederick C. wrote:

On 15 Nov 2007, at 11:25, Nadeesha M. wrote:

<% end %>

when the cubmit button is clicked it should go the a new controller
called fileuploader which has method name “create”

if the create action isn’t on the same controller as the create
action, you need to specify it, ie
:url => { :action => “create”, :controller =>
‘some_other_controller’ }

Fred

thanks a lot for it pal it works.

now another prob PAL,

in my create method their is a condition to forward to two different
pages according to the condition value.

if ( condition )

render_action ‘success’
#file is in the given format

else

render_action ‘new’
#file is not in the given format

end

when i use this it give a error as
Template is missing

Missing template
/home/neranjan/Desktop/codes/RubyOnRails/codes/app/views/file_uploding/new.rhtml

my success.rhtml and new.rhtml pages are in a different folder called
“test”(that one is in the app folder) so how to over come this problem…

On 15 Nov 2007, at 12:01, Nadeesha M. wrote:

my success.rhtml and new.rhtml pages are in a different folder called
“test”(that one is in the app folder) so how to over come this
problem…

To be quite honest, I’m not sure why you’ve put these in different
controllers. That said you can do stuff like render :template =>
‘some_controller/some_action’

Fred

Frederick C. wrote:

On 15 Nov 2007, at 12:01, Nadeesha M. wrote:

my success.rhtml and new.rhtml pages are in a different folder called
“test”(that one is in the app folder) so how to over come this
problem…

To be quite honest, I’m not sure why you’ve put these in different
controllers. That said you can do stuff like render :template =>
‘some_controller/some_action’

Fred

ok pal thanks a lot for the advice.

i wrote in a different controls so the function i wrote can be used by
many places with out repeating the same code again and again in
different controls.

so here the problem i am facing now is, according to the given condition
i have to send the error messages to back to the calling page. so do do
such a thing i could not found a working redirection method.

found some sample coding that would satisfied my need in the following
url
http://snippets.dzone.com/posts/show/1052

those codes work properly.

but at thir i had to hard codes the going back codes. like
redirect_back_or_default :controller => “myfuel”, :action => “index”

so when some one used my above controle code they will face problem like
finding a given path.

so want i want to do is when some one use my controller and do the
validation it should be able to send the feed back to calling page with
out we have to specifically saying to it.
eg

redirect_back_or_default :controller => “…”, :action => “…”
the controller and the action will be able to get from the data that
comes when it calling my controller

so hope u guys got the point what i am going to say and hope i may get a
good reply…

Thorsten M. wrote:

if i got it right you may use something like that:

<%= link_to “text”, mycontroller_path(:request_uri =>
request.request_uri) %>

this will hand over the uri of the actual site to your controller
which in turn can then redirect to calling page:

redirect_to params[:request_uri]

another very simple approach is just
redirect :back

but this only works, if the user hasn’t disabled referrers
(that’s not very often, but some ppl do)

when i used the command in side the form tag

<%= link_to “text”, mycontroller_path(:request_uri => request.request_uri) %>

it gives a error as

undefined method `mycontroller_path’ for
#<#Class:0xb758e3c0:0xb758e398>

does any one know why is that

because mycontroller should be the name of your controller, i used it
only as example (we use path generator functions of the edge version,
since they’re more convenient than this :url => {…} stuff

plus we use RESTful routing

so the details, how to call your controller and hand over attributes may
be different.
the trick without that is to hand over request.request_uri as an
attribute in your link. however you decide to manage that :slight_smile:

if i got it right you may use something like that:

<%= link_to “text”, mycontroller_path(:request_uri =>
request.request_uri) %>

this will hand over the uri of the actual site to your controller
which in turn can then redirect to calling page:

redirect_to params[:request_uri]

another very simple approach is just
redirect :back

but this only works, if the user hasn’t disabled referrers
(that’s not very often, but some ppl do)

Thorsten M. wrote:

because mycontroller should be the name of your controller, i used it
only as example (we use path generator functions of the edge version,
since they’re more convenient than this :url => {…} stuff

plus we use RESTful routing

so the details, how to call your controller and hand over attributes may
be different.
the trick without that is to hand over request.request_uri as an
attribute in your link. however you decide to manage that :slight_smile:

<% form_for :form_file, :url => { :action => “create”, :controller
=>“file_uploding” }, :html => { :multipart => true } do |g| %>

<%= g.file_field :upload_file %>

<%= submit_tag :Up_load_now %>

<%= g.hidden_field :condition_file_type, :value => "APPLICATION" -%> <% end %>

my form code is like this but i tried to add ur code but could not find
a way to do it… if can pls help

Nadeesha M. wrote:

Thorsten M. wrote:

because mycontroller should be the name of your controller, i used it
only as example (we use path generator functions of the edge version,
since they’re more convenient than this :url => {…} stuff

plus we use RESTful routing

so the details, how to call your controller and hand over attributes may
be different.
the trick without that is to hand over request.request_uri as an
attribute in your link. however you decide to manage that :slight_smile:

<% form_for :form_file, :url => { :action => “create”, :controller
=>“file_uploding” }, :html => { :multipart => true } do |g| %>

<%= g.file_field :upload_file %>

<%= submit_tag :Up_load_now %>

<%= g.hidden_field :condition_file_type, :value => "APPLICATION" -%> <% end %>

my controller is like this

def create

  @temp_file = @params["form_file"]["upload_file"]
  @file_name  = @temp_file.original_filename
  upload_file_type  = @temp_file.content_type
  condition_file_type = @params["form_file"]["condition_file_type"]
  upload_file_type = upload_file_type.chop.upcase


if (@temp_file !="")
   if  ( ckeck_file(upload_file_type, condition_file_type) )
   f = File.new("./uploads/nad/#{@file_name}", "wb");
   f.write (@temp_file.read);
   f.close;


  # what i want here is from here send success msg to calling form

   else

     #file is not in the given format
     # what i want here is from here send error msg to calling form

   end

else

       #their is no file to be upload
       # what i want here is from here send error msg to calling 

form

 end

def ckeck_file(upload_file_type , condition_file_type )

      file_types = ["JPG","JPEG","GIF","PNG","MSWORD","PDF"]

      file_types.each do |check|
          check_string=condition_file_type+"/"+check
           puts check_string
          if (upload_file_type.eql?(check_string))
            puts check_string
            return true;
          end
      end
       return false;
   end

my form code is like this but i tried to add ur code but could not find
a way to do it… if can pls help

Thorsten M. wrote:

in a form you could use a hidden field to hand over this param

<%= hidden_field_tag :request_uri, request.request_uri %>

THANKS A LOT PAL IT WORKS

hey but again a little prob…

in those conditions i want to i want to send the error or success to the
back to the page it calls i tried some coding bt i wont display the msg
send by the control.

does not know if my way is correct
and idea how can i over come that problem

it’s most likely the flash object you wanna use there

in the controller:

flash[:return_msg] = “my message”

in the view:

<%= flash[:return_msg] if flash[:return_msg] %>

in a form you could use a hidden field to hand over this param

<%= hidden_field_tag :request_uri, request.request_uri %>

Thorsten M. wrote:

it’s most likely the flash object you wanna use there

in the controller:

flash[:return_msg] = “my message”

in the view:

<%= flash[:return_msg] if flash[:return_msg] %>

Thanks a it PAL it works.

bythe way to send a error msg to the other page the use of flash object
is a correct way or not. bz i am new to the RUBY i do not know weather i
use a correct concept or not. is their a define way to send error msg in
RUBY.??

:slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile:

bythe way to send a error msg to the other page the use of flash object
is a correct way or not. bz i am new to the RUBY i do not know weather i
use a correct concept or not. is their a define way to send error msg in
RUBY.??

“Flash” is an internal storage container (actually a kind of hash) that
Rails uses for temporary data between actions. Items stored in the flash
exist for the duration of exactly one action, and then they’re gone.

i used it in this case, because you wanted to send a message if error or
not

normally you would add errors to your ActiveRecord object
if your model is named User (and an instance @user) , then you can do
things like this:

add an error to an attribute:
@user.errors.add(:name, “name can’t be blank”)

add an error to the ‘whole’ record:
@user.errors.add_to_base(“another error”)

there are ActionView::Helpers::ActiveRecordHelper to show errors in the
view:
error_message_on @user, :name
and:
error_messages_for @user

you may find this helpful:

http://www.sitepoint.com/books/rails1/freebook.php