bootstrap modal - How to pass the parameter from view to controller in Rails -


i new rails , working on simple application "tasklist" (to list).

in app, want categories tasks based different type of category(shopping, todo - user can create own category). created separate model user, category , task , each task linked 1 category.

in view (users/show.html.erb -n side render view category , task), have listed categories in left side , open tasks in right side. want make categories links, when user select 1 categories, tasks linked category type displayed in right side.

i understand how normal link_to works when takes new page. understand how button works in bootstrap. not able identify how can pass category selection controller, can pull task category matches user selected.

thanks help.

you need pass category parameter sort of evaluation function, filtering appropriate categories. can either done javascript or rails:

rails

<% category.all.each |category| %>   <%= link_to category.name, users_path(user, category: category.id) %> <% end %> 

this pass category param users#show action:

def show   @user = user.find params[:id]   @categories = @user.categories   @categories = @categories.where(category: params[:category]) if params[:category] end 

javascript

if wanted explorative, you'd want use js keep functionality on view only:

#app/assets/javascripts/application.js $(document).on("click", "a.category", function(e){   var id = $(this).data("category_id");   $(".todos a").not("[data-category_id=\"" + id + \""]").hide(); });  #app/views/users/show.html.erb <% category.all.each |category| %>   <%= link_to category.name, users_path(user, category: category.id), class: "category", data: { category_id: category.id } %> <% end %>  <div class="todos">   <% @user.todos.each |todo| %>     <%= link_to todo.title, todo, data: { category_id: todo.category_id } %>   <% end %> </div> 

this allow click "category" , have list of "todos" change suit.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -