Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the name of controller in URL in Rails

I have a controller

 emppedes

Its fine when i want to call this in url i see

localhost:3000/emppedes

and whole the content related to it appears.

But can i match this controller to others name in rails so that when i click in it I can get in URL like

localhost:3000/employees

without changing the controller inside but outside in url you can see that. I mean can i code somewhere like

 `emppedes will display as employees in URL.`

Is it possible. May be my question is stupid but I want to know whether it is possible or not. In edit i have two send two different id and in controller also for update i have to send two id. For edit my code is like

<%= link_to 'Edit', { :action => "edit",:id => @emppede.id,:ad => @id},:class=>"btn btn-success" %> |

since i have two handle two id in controller Also for update

 @id= @emppede.ad

if @emppede.save
        format.html { redirect_to :action => :index, :id => @emppede.ad }
        format.json { render json: @emppede, status: :created, location: @emppede }

How can i send two params :id and :ad both in rails path formate? Since my controller is like this

def index
         @id = params[:id]
      @data = Emppede.where(:ad => @id)
    if @data.count > 0
      @data.each do |data|
        @ids= data.id
         end
      redirect_to :action => :show, :id => @ids, :ad => @id
     else
      redirect_to :action => :new, :id => @id
    end
  end
like image 525
regmiprem Avatar asked Jan 22 '26 11:01

regmiprem


2 Answers

Yes, you can just specify the controller to use for any given resource:

resources :employees, :controller => "emppedes"

Or if you prefer the Ruby 1.9 syntax:

resources :employees, controller: "emppedes"

For more details, see Rails Guide: Routing.

like image 156
gcastro Avatar answered Jan 25 '26 20:01

gcastro


What you will want to do is pass in the :path option

resources :employees, :path => "emppedes"

This replace all your route references with /employees to /emppedes

See: http://guides.rubyonrails.org/routing.html, Section 4.7 Translating Paths

like image 29
vijikumar Avatar answered Jan 25 '26 19:01

vijikumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!