Re: [Rails] Re: [QUESTION] How to have different routes ids on different routes for the same resources?

2017-04-21 Thread Maurizio De Santis
>
> resources :posts, param: :slug


FWIK this just changes the name of the parameter passed to the controller,
so if you write post_path(Post.first) you will have a request like
/posts/#{post.to_param} but in the controller instead of have param[:id]
you have param[:slug]

--

Maurizio De Santis

2017-04-20 22:27 GMT+02:00 :

> You can also do something like this If i get it right,
>
> resources :posts, param: :slug
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/rubyonrails-talk/rneoBmxG4QY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/rubyonrails-talk/ffd0916e-d658-4cb9-b24f-
> c4b3ebb52454%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CA%2B_M_Jdcs3E51oQfc%2BAQpBbr%3D3KO9kMZOGn04pu2ATsUQUe_0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: [QUESTION] How to have different routes ids on different routes for the same resources?

2017-04-21 Thread batuhanwilhelm
You can also do something like this If i get it right,

resources :posts, param: :slug

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/ffd0916e-d658-4cb9-b24f-c4b3ebb52454%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Re: [QUESTION] How to have different routes ids on different routes for the same resources?

2017-04-20 Thread André Orvalho
Thats great!

I am glad you shared this.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CANrYT%2BU7ORvezXs94RRiXYq7GS%3Ds1Wafbd-rLpdfQdVbdeAyKA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: [QUESTION] How to have different routes ids on different routes for the same resources?

2017-04-20 Thread Maurizio De Santis
I have to say that Rails is great. 5.1 introduces a wonderful feature for 
my need: direct 
http://edgeapi.rubyonrails.org/classes/ActionDispatch/Routing/Mapper/CustomUrls.html#method-i-direct

Now in config/routes.rb I can write:

# Content model includes FriendlyId, so content_path(Content.first) calls 
record.to_param using the slug
resources :contents

direct 'edit_admin_content' do |record, options|
  # Here I specify to use the record id, so the resource url will fit 
better with admin section purposes
  options.merge controller: '/admin/contents', action: :edit, id: record.id
end

Same for actions :show, :update and :destroy. Problem solved!

Il giorno giovedì 20 aprile 2017 15:49:55 UTC+2, André Orvalho ha scritto:
>
> I don't think it is an hack what you are doing.
>
> To actually have routes receiving different types of ids you probably 
> needed to change how those helpers are generated by rails.
> That means you might have to monkey patch rails.
>
> The alternative rails is giving you to be able to do this is by doing 
> this: admin_content_path(id: content.id)
>
> So it allows you to pass to override the id passed as argument.
>
> I am sorry but I dont think there is a way around this.
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/2c64950f-5faa-458f-b0f5-2bfdd4017586%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: [QUESTION] How to have different routes ids on different routes for the same resources?

2017-04-20 Thread André Orvalho
I don't think it is an hack what you are doing.

To actually have routes receiving different types of ids you probably 
needed to change how those helpers are generated by rails.
That means you might have to monkey patch rails.

The alternative rails is giving you to be able to do this is by doing this: 
admin_content_path(id: content.id)

So it allows you to pass to override the id passed as argument.

I am sorry but I dont think there is a way around this.



-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/a9b4b875-02c3-4460-a410-f22aede05fd5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.