Generate a `link_to` to the controller action `edit`, dynamically
You can write routes using the "array style" like this :
= link_to "Edit", [:edit, @your_resource]
Rails dynamic link_to's
You have
<%= link_to job.id, job %>
Here second option specifies your url or path helper. You are getting this error because there is no job_path helper for your routes
To check all the url or path helpers do rake routes in your terminal. It will give you output which looks something like
Prefix Verb URI Pattern Controller#Action
customer_job GET /customers/:customer_id/jobs/:id(.:format) jobs#show
So replace your link with
<%= link_to job.id, customer_job_path(@customer,job) %>
UPDATE:
Referring to your comment:
@customer is an instance variable of your Customer model which you would have defined in your controller action(since you are using it in your view). Instance variables defined in your controller action are automatically available for its view. For details you should read docs
create a dynamic link text and link in Html.ActionLink()
It should be like:Html.ActionLink("Details", "Country", new { country = @item })
Or try like this:
<a href="@Url.Action("Details", "Country", new { country = @item })">@item</a>
you are getting null, as you are not passing the parameter to your action method.
Dynamically generate link_to for different models using common partial - Rails 4
You can use layouts with your partials. See the API docs for more details.
Rendering pictures with layouts
First, rewrite pictures/index.html.erb
to:
<%= render partial: 'picture', layout: 'shared/index_common_grid', collection: @pictures, as: :object %>
Second, rewrite shared/index_common_grid.html.erb
to:
<div class="col-sm-4 pull-left">
<div class="thumbnail">
<div class="caption">
<h4><%= object.title.capitalize%></h4>
<p class="text-muted">
<%= yield %> | <span class="pull-right"><%= show_formatted_date(object.created_at)%></span>
</p>
</div>
</div>
</div>
Thrid, create pictures/_picture.html.erb
:
<%= link_to "Edit", [:edit, current_user, @request, @shop, picture]%>
| <%= link_to "Delete", [current_user, @request, @shop, picture], :data=>{:confirm=>"Are you sure ?"}%>
Adding other types of objects
If you want to render other types of objects (menus in your example) then:
- Add
menus/index.html.erb
with a content similar topictures/index.html.erb
(replacepicture
and@pictures
withmenu
andmenus
). - Add
menus/_menu.html.erb
with links rendered appropriately for menus.
Create dynamic links in the navigation panel
if the controller and action don't match an existing controller and action then no href will be rendered. I suspect that @category.DisplayName does not match any actual action name on your home controller. Seems more likely that you have an action named Category that expects a parameter corresponding to the @category.DisplayName so it should be passed as a route parameter not as the action name
@foreach (var category in categories)
{
<li><a asp-controller="Home"
asp-action="Category"
asp-route-category="@category.DisplayName">@category.DisplayName</a></li>
}
Related Topics
An Error Occurred While Installing Curb (0.8.5)
How to Completely Wipe Rubygems Along with Rails etc
Bundle Install Not Running from My Post-Update Hook
Properly Using Log4R in Ruby Application
What's Gem Can Operate Excel on Linux
Ruby String#Scan Equivalent to Return Matchdata
Git Post-Receive Hook Not Running Bundle Install
Use Same Controller for Multiple Routes
Ruby Inject with Index and Brackets
How to Start Using Xiki in Emacs
Using Rubyzip to Add Files and Nested Directories to a Zipoutputstream