logo
down
shadow

How To Create Action Items For Specific Customer In Rails


How To Create Action Items For Specific Customer In Rails

By : Mark
Date : November 18 2020, 01:01 AM
Hope that helps The way I would do this is setup your routes so that action_items are nested under the client, something like so:
code :
# /clients/13/action_items
resources :clients do
  resources :action_items
end
class Client < ActiveRecord::Base
  belongs_to :user
  has_and_belongs_to_many :action_items
end
class ActionItem < ActiveRecord::Base
  has_and_belongs_to_many :clients
end
class User < ActiveRecord::Base
  has_many :clients
end
class ActionItemsController < ApplicationController
  before_action :get_client

  def index
    @action_items = @client.action_items.all
  end

  def new
    @action_items = @client.action_items.new
  end

  def create
    @action_item = @client.action_items.new(action_items_params)
    if @action_item.save
      redirect_to(:action => 'show', :id => @action_item.id, :client_id => @client.id)
    else 
      redirect_to(:action => 'new')
    end
  end

  # and other actions....

  private

  def get_client
    @client = current_user.clients.find(params[:client_id])
  end
end
# /action_items
resources :action_items

resources :clients do
  # /clients/13/action_items
  resources :action_items
end
class ActionItemsController < ApplicationController
  before_action :get_owner

  def index
    @action_items = @owner.action_items.all
  end

  # ... other stuff

  private

  def get_owner
    if params[:client_id].present?
      @owner = current_user.clients.find(params[:client_id])
    else
      @owner = current_user
    end
  end
end
def destroy
  item = @owner.action_items.find(params[:id])
  item.destroy
  if params[:client_id]
    redirect_to client_action_items_path(params[:client_id])
  else
    redirect_to action_items_path
  end
end
<% if params[:client_id].present? %>
  <%= link_to 'Delete action item', client_action_item_path(params[:client_id], @action_item), :method => 'delete' %>
<% else %>
  <%= link_to 'Delete action item', @action_item, :method => 'delete' %>
<% end %>


Share : facebook icon twitter icon
Rails: Point several nested routes to one customer controller action

Rails: Point several nested routes to one customer controller action


By : 4rnie1
Date : March 29 2020, 07:55 AM
wish helps you My I suggest that you create a new controller to handle this? The advantage is that you can map the route to this controller on any models you want the "remove association" on.
For example:
code :
# RemoveController.rb
class RemoveController < ApplicationController
  def destroy
     # inplement the logic for deletion. You can use refection to implement 
     # this function only once for all the applied associations.    
  end
end

# routes.rb
resources :companies do
  resource :requests do
    resource :remove, :controller => :remove, :only => [:destroy]
  end
end
company_requests_remove DELETE /companies/:company_id/requests/remove(.:format)          remove#destroy
# routes.rb
resources :companies do
  resource :requests do
    resource :remove, :controller => :relationship, :only => [:destroy]
    resource :create, :controller => :relationship, :only => [:create]
  end
end

company_requests_remove DELETE /companies/:company_id/requests/remove(.:format)        relationship#destroy
company_requests_create POST   /companies/:company_id/requests/create(.:format)        relationship#create
Is it possible to have params[:customer] created in index action (rails 3.2.12)?

Is it possible to have params[:customer] created in index action (rails 3.2.12)?


By : Roberto T.
Date : March 29 2020, 07:55 AM
Hope that helps You can ensure it exists (and is a Hash) by using this params[:customer] ||= {}
Check if customer has purchased 5 specific items

Check if customer has purchased 5 specific items


By : ERRAHMANI Hossein
Date : March 29 2020, 07:55 AM
hope this fix your issue You can determine the customers who have purchased the three items with:
code :
select customerid
from purchases 
where itemid in (1,2, 3)
group by customerid
having count(distinct itemid) = 3;
update p
    set timespurchased = 0
    from purchases p join
         (select customerid
          from purchases 
          where itemid in (1,2, 3)
          group by customerid
          having count(distinct itemid) = 3
         ) c
         on p.customerid = c.customerid;
Rails 4, how to do a controller specific action in create.js.erb

Rails 4, how to do a controller specific action in create.js.erb


By : Shaa
Date : March 29 2020, 07:55 AM
it should still fix some issue I finally got it:
It was always calling the same controller, the create. I needed to create an instance variable in said controller, to access it through this file. This is my final code:
code :
$(".cart-text").html("<%= escape_javascript(render 'layouts/cart_text') %>")
<% if @product_type_name == "Fosa" %>
    <% product_type = ProductType.where(name: 'Fosa') %>
    <% @products = Product.where(product_type: product_type) %>
<% elsif @product_type_name == "Féretro" %>
    <% product_type = ProductType.where(name: 'Féretro') %>
    <% @products = Product.where(product_type: product_type) %>
<% else %>
    <% actions = ProductType.where("name not in ('Fosa','Féretro')").uniq.pluck(:id) %>
    <% actions = -1 if actions.length == 0 %>
    <% product_type = ProductType.where('id IN (?)',actions) %>
    <% @products = Product.where(product_type: product_type) %>
<% end %>
<% @invoice_product = current_invoice.invoice_products.new %>
$(".list_products").html("<%= escape_javascript(render 'homes/list_products', products: @products, invoice_product: @invoice_product) %>")
How to create customer & items in quickbook through api in rails?

How to create customer & items in quickbook through api in rails?


By : Akshay Raut
Date : March 29 2020, 07:55 AM
Hope that helps Start here:
https://developer.intuit.com/
code :
{
    "BillAddr": {
        "Line1": "123 Main Street",
        "City": "Mountain View",
        "Country": "USA",
        "CountrySubDivisionCode": "CA",
        "PostalCode": "94042"
    },
    "Notes": "Here are other details.",
    "Title": "Mr",
    "GivenName": "James",
    "MiddleName": "B",
    "FamilyName": "King",
    "Suffix": "Jr",
    "FullyQualifiedName": "King Groceries",
    "CompanyName": "King Groceries",
    "DisplayName": "King's Groceries",
    "PrimaryPhone": {
        "FreeFormNumber": "(555) 555-5555"
    },
    "PrimaryEmailAddr": {
        "Address": "jdrew@myemail.com"
    }
}
{
    "Customer": {
        "Taxable": true,
        "BillAddr": {
            "Id": "112",
            "Line1": "123 Main Street",
            "City": "Mountain View",
            "Country": "USA",
            "CountrySubDivisionCode": "CA",
            "PostalCode": "94042"
        },
        "Notes": "Here are other details.",
        "Job": false,
        "BillWithParent": false,
        "Balance": 0,
        "BalanceWithJobs": 0,
        "CurrencyRef": {
            "value": "USD",
            "name": "United States Dollar"
        },
        "PreferredDeliveryMethod": "Print",
        "domain": "QBO",
        "sparse": false,
        "Id": "67",
        "SyncToken": "0",
        "MetaData": {
            "CreateTime": "2015-07-23T10:58:12-07:00",
            "LastUpdatedTime": "2015-07-23T10:58:12-07:00"
        },
        "Title": "Mr",
        "GivenName": "James",
        "MiddleName": "B",
        "FamilyName": "King",
        "Suffix": "Jr",
        "FullyQualifiedName": "King's Groceries",
        "CompanyName": "King Groceries",
        "DisplayName": "King's Groceries",
        "PrintOnCheckName": "King Groceries",
        "Active": true,
        "PrimaryPhone": {
            "FreeFormNumber": "(555) 555-5555"
        },
        "PrimaryEmailAddr": {
            "Address": "jdrew@myemail.com"
        },
        "DefaultTaxCodeRef": {
            "value": "2"
        }
    },
    "time": "2015-07-23T10:58:12.099-07:00"
}
Related Posts Related Posts :
  • In Ruby on Rails, After send_file method delete the file from server
  • An error occurred while installing nokogiri (1.6.6.2), and Bundler cannot continue
  • How to setup nested routing for a self referencing controller in Rails 4
  • middleman app it is possible to create a contact form?
  • How to refactor this piece of code
  • How can I know if a user has access to all or just some resources with Cancan?
  • How can I run a ruby class from rake file?
  • Send JSON data as post method from rails controller to a web service
  • How to test Controllers under different namespaces and why this test fails?
  • rspec expect condition OR condition
  • Page loads unnecessary queries Ruby On Rails
  • Why "bundle install" try to install outdated version of gems?
  • Rails - Customize model validation error messages but without a database
  • When to switch from cucumber to rspec in the BDD cycle for a login procedure
  • Multipart response for web service
  • How to hide Add new option in Rails Admin
  • Override CollectionProxy find method
  • Rails 4 simple_form has_many through check boxes not saving
  • ruby on rails authentication using devise gem
  • Rails iteration over arrays and hashes
  • Creating inline date_select dropdowns using simple_form and zurb foundation
  • NameError in SongsController#index uninitialized constant Song::FriendlyId
  • Rails how to improve if record exists?
  • omniauth custom request phase form
  • Rails 5 - Saving the absolute current url via a button to a cookie?
  • How can / should I override the `build` method for a my model?
  • Install Rails Failed on OSX 10.8.4
  • ruby on rails - undefined method valid?
  • Users Registration on POST
  • Rails application variables in carrierwave store_dir
  • How to customize simple_form for json nested hash
  • Couldn't find file 'jquery', Sprockets::FileNotFound in StaticPages#home error
  • How should I use the alias_method_chain for the build method?
  • how to create two custom registration forms in devise?
  • Rails 4 link_to Destroy not working in Getting Started tutorial
  • How does ruby on rails dynamically define `find_by_id`, `find_by_name` methods?
  • JBuilder dynamic keys for model attributes
  • `initialize': No such file or directory - getaddrinfo (Errno::ENOENT) when Rails new app
  • What is the Ruby equivalent of Node.js' socket.io?
  • Where rails store standard helpers?
  • how to check expected result matches any of give values in rspec?
  • Form submission to create multiple objects
  • Simple Twitter Login with Rails and Email confirmation
  • Where should helpful functions for my controller go in Rails?
  • Using session variable in the Model or the other way
  • Why can't I have ruby code and comments in Embedded Ruby?
  • Rails: How can I make an object available in all views?
  • Cannot enter simply form information into SQLite DB (Rails)
  • Rails - Retain form values on failed submission. Getting "First argument in form cannot contain nil or be empty&quo
  • How to handle STI and build related models automatically?
  • Suppress an error when saving a record in Rails
  • Rails AJAX reload the page. Why?
  • How to pass user attributes to action mailer
  • Custom Validator to Prevent an appointment from being scheduled too early in day?
  • Postgres Enable TCP/IP Connection
  • How do I avoid the circular argument reference warning in activesupport
  • Unable to push to heroku master because of rails/spring version error
  • deep nested routes in rails
  • Best approach to Users Profile Images in Rails App
  • RailsInstaller: Can I maintain the gem fold when re-installing a new version?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org