0

I am trying to ensure that each job has the correct link when a user clicks on it.

The issue I am having is that I keep getting the error Couldn't find job without an ID.

In my view I have the following code:

 <% @jobs.group_by{|x| x.created_at.strftime("%d %b. %Y")}.each do |date,jobs_on_that_date| %>
   <section class="date"><%= date %></section>
   <section id="top-job">
      <% jobs_on_that_date.each do |job| %>
   <section id="job-wrapper">
  <%= link_to url_with_protocol(@link.job_url), :target => '_blank' do %>
  <section id="job">
        <%= job.title %> - <%= job.company %>
        <%= job.salary %>
        <%= job.location %> 
        <%= job.job_type %>
  </section>
  </section>    
  <% end %>
  <% end %>
  </section>
  <% end %>

In my controller I am creating an object called @link as follows:

 def index
  @user = current_user
  @jobs = Job.where('created_at > ?', 30.days.ago).reverse
  @link = Job.find(params[:id])
 end

Finally I have the following Routes setup.

 JobappV2::Application.routes.draw do

   devise_for :users

   resources :jobs

   resources :users do
      resources :jobs
   end

   root :to => 'jobs#index'


   end

If I use @link = Job.find(2) this works but every job ends up with the link input by the job with id 2.

Thanks in advance for any help!


The global structure looks good to me. You need a module to write a setup.py script to install your package such as setuptools. This will allow installation and distribution of the package. See also Pypi for distribution of the package. Typically, you can :

sudo setup.py install

to install your package at the system level. Or you can :

sudo setup.py install --prefix=~/local 

to install at the user level. But then you have to add ~/local/lib/python/site-packages to your PYTHONPATH. But it has to be done only once for all packages installed by this user.

If your package is stored on PyPI, you can on any machine do :

easy_install mypackage

to auto-magically install the package.

Even better you can make your packages only visible in isolated python "virtual environment" using virtualenv. This allow for testing of various packages and versions on the same computer a breeze.

You can also add README files and such at the package root level.

4

1 に答える 1

1

params[:id]ですか?

あなたがあなたのコントローラーでそうするならばraise params[:id].inspect、あなたはそれがであるとわかるだろうと私は思うnil。その上、作成することのポイントは何@linkですか?job.job_url代わりにあなたのビューに入れるだけです@link.job_url

于 2012-08-03T10:18:21.027 に答える