I'm a student intern and I have to improve the website of the company. I created a partial in Ruby on Rails, and I want to use it multiple times on the same page. I have some nav tabs and depending on the active tab, the same partial should be displayed with different parameters.
What I wanted to do is to re render my partial when the user changes the active tab. So I searched on the net how to re render a partial using rails and js, and it seems that I have to use ajax (with respond_to in rails). So I did it and somewhere else on the website there is a similar thing, but it didn't work for me and I'm pretty sure, it's a routing problem, because on the website it's done on a specific page (beneficiaries/1
for instance), but I have to do it on stories/new
Here is the link which call the function to re render the code :
= link_to 'Activities', modify_tab_new_project_story_path(@project), method: :post, remote: true, :style => 'text-align: center;'
Then in the routes.rb file : (I tried a lot of different things but none of them worked)
resources :projects, only: [:show, :destroy] do
resources :stories do
post :modify_tab, on: :new
end
end
My controller :
def change_tab
respond_to do |format|
format.js
end
end
And finally I'm redirected to :
http://localhost:3000/projects/issue-1004/stories/new/modify_tab
instead of staying in the same page.
In addition I get this error
whereas I use the method post.
It's really confused in my brain so I probably made some mistakes.
the thing which works on the website :
Here is the view :
= form_tag create_note_charity_beneficiaries_path(@charity), method: :post, remote: true, id: 'note_form' do
Then the routes.rb :
resources :charities, except: :index do
resources :beneficiaries do
collection do
post :create_note
end
end
end
And finally the controller :
def create_note
note = Note.create(params[:note])
@beneficiary = note.beneficiary
respond_to do |format|
format.js
end
end
There is also a create_note.js.erb file and I've created one too, but the problem come before this file so I didn't put it here.
Hope someone could help me
Thanks