Getting the ID of a Model that Uses Nested Routes and Permalinks in Rails -


So I had my ID set with ID like:

  resources: studio Doing Resources: Booking Finished  

This gave me the route of the index (which later I am going to use Jasonson to get the calendar for each studio.

  Studio_Bookings GET / Studio /. Studio_ID / Bookings (. Format: Booking # Index)  

This is good, but I was getting rid of the ID and wanted to use a user account instead to change it to a friendly URL.

Namespace: Studio, Path = & gt; ; '/: Permalink' Resource: Complete booking:

I am getting now

  Get Studio_bookings /: paramlink / bookings (.format) Studio / Booking # Index  

Great! How do I want to see my URL, though, now: Not anywhere on the id route I have found

  Booking can not be found without ID  

This is not being passed too. is there any way? To pass: IDs in the URL without actually using the URL? Otherwise, can I change the primary key from: id: permalink to fix it?

I tried changing my controller from

  @studio = Studio.find to Params [: id])  

  @studio = studio.find (Parameters [: permalink])  

but gives me

  id Booking with '= 40frost  

has not been found which tells me what I am doing is not actually what to do? It is trying to keep permalink in the form of ID, although I am asking the rail to see the paramike, it still appears that it is looking at ID.

Hopefully my problem is clear: Essentially - how can I pass the ID, so that it knows that it is not displayed in the studio url If there is some controller magic then I can be flexible instead.

Here's my controller for good measure

  class studio :: booking controller & lt; ApplicationController before_action: set_booking, only: [: show, edit, update: deleted] #GET / booking #GET /bookings.json dnf index @ studio = studio.find (param [: permalink]) @ bookings = booking. Where ("Studio_ID = & gt; 'Studio.ID'") End # GET / Booking / 1 # GET / Bookings / 1.Jason Def Show End # GET / Booking / New Def New @ Booking = Booking.New and # GET / Booking / 1 / edit def editing end # POST / booking # POST / bookings.json def @ booking = booking.news (booking_parms) response_to do | Format | If booking @ save.change format.html {bookmark_to @booking, notice: 'booking was successfully created.' } Format.json {Render Action: 'Show', Status :: Created, Location: @Booking} and Format Html {animation: 'new'} format.json {json: @ booking. Errors, Status :: unprocessable_entity} End & End # Patch / Pet / Booking / 1 # Patch / Put / Bookings / 1 JSN DIF Update Reply-To-Do | Format | If @ booking.update (booking_parms) format.html {redirect_to @booking, notice: 'booking was successfully updated.' } Format.json {head: no_content} else format.html {render action: 'edit'} format.json {json: @ booking Errors, Status :: unprocessable_entity} End & # DELETE / Booking / 1 # Deletion / Booking / Booking 1.json DEF @. Update response_to do format | Format.html {redirect_to bookings_url} format.json {head: no_content} Use Callback to share common setup or interruptions between end-end personal # functions Def set_booking @booking = booking.find (params [: permalink]) End # Scary Do not trust the criteria from the Internet; Allow only through white list Def booking_param params.require (booking) .Permit (: start_time,: end_time ,: studio_id,: engineer_id,: title, allday) End end  

you just You can model, or you can

  self.primary_key = 'permalink' in studios  
  Def index @studio = Studio.find_by permalink: params [: permalink] @bookings = Booking.where (studio_id: @ studio.id) End  

Depends if you are just locally Want to change behavior or always want to describe the studio model by permalink.

Hope that helps!


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -