How to set up clickable boxes (Ruby) [closed] - ruby-on-rails

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to be able to set up kind of a navigatable menu. So like, there could be three boxes, each one with a number on it, and if you click on one of them it executes a certain code or takes one to another page. I feel dumb for not knowing how to do this, but I have success in everything but this, thanks so much!

It depends on what you want, but simply, you'd need this:
#config/routes.rb
resources :pages
#app/views/elements/nav.html.erb
<% pages = %w(home about contact) %>
<% for page in pages do %>
<%= link_to "Home", page_path(page) %>
<% end %>
You'll be able to style the boxes to look like buttons using CSS

Related

drawerOpened property dont work in vaadin [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I use litElement with vaadin and have next code
<vaadin-app-layout .drawerOpened='false'>
<vaadin-drawer-toggle slot="navbar" ></vaadin-drawer-toggle>
<vaadin-tabs selected="-100" slot="drawer" orientation="vertical" theme="minimal" style="margin: 0 auto; flex: 1;">
${this.renderTabsDependOnStatusAccess()}
</vaadin-tabs>
<div class="content" >
<div id="outlet"></div>
</div>
</vaadin-app-layout>
but my vaadin-drawer-toggle component is still open, how can I make it private by default and wats wrong with my example
I've not used this component, but I'll guess that in JS it's drawerOpened while in HTML it's drawer-opened. Also, boolean attributes are usually present or not, so instead of drawer-opened="false" you probably just remove it. Plain drawer-opened would be true.
If this HTML or in the LitElement render()? In the latter you may want to use ?drawer-opened="${this.isDrawerOpen}" and toggle a property this.isDrawerOpen

Razor view Html.ActionLink icon [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I need to add an icon near myLink in razor view,
in .html page i use ` Requête optimisée.
Now i have
#Html.ActionLink("Requete optimisée", "Index", "Requete")
Dont know where to add my icon .
I wouldn't use ActionLink and would do the following:
<a href="#Url.Action("Index","Requete")" class="my-link-class">Requete optimisée
<div class="my-icon"><img src="#Url.Content("~/icon.jpg")" alt="Icon Image" /></a>
More code but also more freedom and control over what is going on.
If you want show an icon just put a img tag before your link:
<img src="~/Content/Images/Image.png" />
#Html.ActionLink("Requete optimisée", "Index", "Requete")
And if you want to display image link then use this:
#Html.ActionImage("Requete optimisée", "Requete", "~/Content/Images/Image.png")

When should I use helpers? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I barely use them in my projects. Is this normal? If I need to return just one line of html, say an image tag for a gravatar, then a helper is great:
def gravatar_for(user, height=90, width=90, alt=user.name + "'s gravtatar")
gravatar_address = 'http://1.gravatar.com/avatar/'
clean_email = user.email.strip.downcase
hash = Digest::MD5.hexdigest(clean_email)
image_tag gravatar_address + hash, height: height, width: width, alt: alt
end
However, if I want to loop through some errors, and return html structure rather than a single line, it quickly gets difficult.
Is a good rule of thumb if you want to return one line of html then use a helper, else use a partial to return more complex html?
First of all, the question is opinion based. So, most likely it will be closed.
Here are several questions on similar subject:
DRYing rails view: partial vs helper
Why shouldn't Helpers have html in them?
Generally speaking, helper is just a way to
Have DRY views
Make clean views and controllers
Generally speaking you can DRY views by moving out some duplicated functionality to controllers. However, as result controllers got cluttered. So, the better way to keep view related helpers in helpers (vs controllers), which you already figure out.
Some Helpers don't touch HTML at all (as example, they may just provide some formatting of numbers etc) or they may generate just one tag (as in your example) or generate piece of HTML code. However, as soon as you are talking about some piece of HTML code, you rather use partials vs helper.

rails how to declare a variable and store a value in html.erb [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
hi i have a value like this in html.erb
<img src="<%= file.title, file_path(file) %>" alt=""/>
but when I placed the above code it throws an error
SyntaxError in Files#index
the error comes on file_path(file) section . Is there a way to accomplish this ? like declare a variable and assign it to something ?
Though I did not get whay you are trying to achieve but you can try to do it like this
<img src="<%= "#{file.title}, #{file_path(file)}" %>" alt=""/>
You should declare file (a better naming is #file) in the controller action which is associated with this view. There you can do whatever you want with your variable.

slim dynamic conditional class [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Just to help other developers, because there is no similar question on SO.
div class=(is_active? ? 'active' : 'inactive')
div class=('active' if is_active?)
See the examples below:
div class=(is_active? ? 'active' : 'inactive')
div class=('active' if is_active?)
The same approach can be used to assign dynamic values to other attributes.
I use array of classes and nil element if there is no need to include class in list, then compact array to remove nil elements and finally join all together.
div class=(["cday", "col-md-1", day.day == 1 ? "col-md-offset-#{day.cwday-1}" : nil].compact.join(' '))
If you have multiple conditions I am doing right now something like
div class=(('foo ' if is_foo?) + ('bar' if is_bar?))
Though I feel it to be a blemish if is_bar? return false and the generated HTML results in
<div class="foo "></div>
(the blemish is the blank character after the foo). If someone had a solution for that would be awesome.

Resources